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

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
register
Chrome – Full support
Chrome 120 (Release date: 2023-12-05)
footnote Full support
Edge – Full support
Edge 120 (Release date: 2023-12-07)
footnote Full support
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote
footnote An incompatible version of this function is available for Manifest V2. See userScripts (Legacy).
Opera – Full support
Opera 106 (Release date: 2023-12-19)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 138 (Release date: 2025-04-29)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

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