userScripts.register()

Registers user scripts for the extension.

Syntax

js
let registeredUserScript = browser.userScripts.register(
  scripts       // array of objects
)

Parameters

scripts

array of userScripts.RegisteredUserScript. Details of user scripts to register.

Each userScripts.RegisteredUserScript object must contain the js property as a non-empty array and a non-empty array in either matches or includeGlobs.

Return value

A Promise fulfilled with no arguments if all the requested user scripts are registered. If any user scripts fail to register or the request fails for another reason, none of the scripts are registered, and the promise is rejected with an error message.

Examples

This snippet registers hello world code into the "myScriptId" execution world to run in all websites matching "*://example.com/*".

js
await browser.userScripts.register([
  {
    worldId: "myScriptId",
    js: [{ code: "console.log('Hello world!');" }],
    matches: ["*://example.com/*"],
  },
]);

Example extensions

Browser compatibility