contentScripts.RegisteredContentScript.unregister()

Você está lendo a versão em inglês deste conteúdo porque ainda não há uma tradução para este idioma. Ajude-nos a traduzir este artigo!

Unregisters the content scripts represented by this RegisteredContentScript object.

Syntax

registered.unregister()

Parameters

None.

Return value

None.

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxOperaFirefox for Android
unregisterChrome No support No
Notes
No support No
Notes
Notes There is a polyfill available.
Edge No support NoFirefox Full support 59Opera No support NoFirefox Android Full support 59

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

Examples

This code toggles a registered content script on a browser action click:

var registered = null;

async function register() {

  registered = await browser.contentScripts.register({
    matches: ["*://*.org/*"],
    js: [{
      code: "document.body.innerHTML = '<h1>This page has been eaten<h1>'"
    }],
    runAt: "document_idle"
  });

}

function toggle() {
  if (registered) {
    registered.unregister();
    registered = null;
  } else {
    register();
  }
}

browser.browserAction.onClicked.addListener(toggle);