User script registration

This extension demonstrates the browser.userScripts.register() API.

The extension includes an API script (customUserScriptAPIs.js) that enables user scripts to make use of browser.storage.local.

To enable a user script to be specified and registered, this extension includes a sidebar action. The sidebar enables you to define the following properties that control the execution of a registered script, with default values provided:

All other properties use their default value.

Clicking “Register script” registers the script by calling browser.userScripts.register().

In this example, only one script can be registered at a time: registering a new script unregisters the active script. The extension does this by keeping a reference to the RegisteredUserScript object returned from browser.userScripts.register(): this object provides the unregister() method.

To try the extension, click “Register script” with the defaults and load http://example.org/ or https://www.mozilla.org/. Then change the pattern or the code and reload these or related pages.