MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-dev-survey-2018-1

Add-ons

contentScripts.RegisteredContentScript.unregister()

Unregisters the content scripts represented by this RegisteredContentScript object.

Syntax

registered.unregister()

Parameters

None.

Return value

None.

Browser compatibility

No compatibility data found. Please contribute data for "webextensions.api.contentScripts.RegisteredContentScript.unregister" (depth: 10) to the MDN compatibility data repository.

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);

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,