userScripts

Use this API to register user scripts, third-party scripts designed to manipulate webpages or provide new features. Registering a user script instructs the browser to attach the script to pages that match the URL patterns specified during registration.

Note: This is documentation for the new API version, available in Firefox for Manifest V3. See userScripts (legacy) for information on the API available for use in Firefox with Manifest V2.

This API offers capabilities similar to scripting but with features suited to handling third-party scripts.

Permissions

To use this API, you need the userScripts permission and host_permissions for sites where you want to run scripts. However, the approach to enabling the use of this API varies between browsers:

Execution worlds

When a user script is registered or updated (using userScripts.register() or userScripts.update()), your extension can set it to run in an isolated USER_SCRIPT world or the MAIN world.

A USER_SCRIPT world provides an isolated execution environment that isn't accessible to a host page or other extensions. This isolation is similar to a content script environment, except USER_SCRIPT worlds cannot access extension APIs.

User scripts can share a USER_SCRIPT world or isolate themselves in a USER_SCRIPT world by setting the worldId property of RegisteredUserScript. The API enables an extension to configure a content security policy (CSP) for a USER_SCRIPT world using userScripts.configureWorld().

In the MAIN world, host pages and other extensions can see and access running user scripts. The worldId property is not supported for MAIN worlds.

These execution world values are defined in ExecutionWorld.

Messaging

Like content scripts and other extension scripts, user scripts communicate with other parts of an extension with messages using runtime.sendMessage() and runtime.connect(). However, extensions receive messages using the dedicated runtime.onUserScriptMessage and runtime.onUserScriptConnect. Dedicated handlers are used as they make it easier to identify messages from user scripts, which are a less-trusted context.

To enable messaging APIs, call userScripts.configureWorld() with the messaging argument set to true before registering a user script.

js
browser.userScripts.configureWorld({
  messaging: true,
});

Extension updates

When an extension updates, user scripts are cleared. To restore scripts, add code to the extension's runtime.onInstalled event handler that responds to the "update" reason.

Types

userScripts.ExecutionWorld

The execution environment for a script injected with userScripts.register() or userScripts.update().

userScripts.RegisteredUserScript

An object returned by getScripts() representing registered user scripts and used as input to register() and update().

userScripts.ScriptSource

The code or a file source for a user script.

userScripts.UserScriptFilter

A list of user scripts to be processed by userScripts.getScripts() or userScripts.unregister().

userScripts.WorldProperties

The configuration of a USER_SCRIPT execution environment.

Methods

userScripts.configureWorld()

Configures a USER_SCRIPT execution environment for the extension.

userScripts.getScripts()

Returns user scripts registered by the extension.

userScripts.getWorldConfigurations()

Returns all the extension's registered world configurations.

userScripts.register()

Registers user scripts for the extension.

userScripts.resetWorldConfiguration()

Resets the configuration for a USER_SCRIPT world registered by the extension.

userScripts.unregister()

Unregisters user scripts registered by the extension.

userScripts.update()

Updates user scripts registered by the extension.

userScripts.execute()

Injects a user script into a target context.

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
userScripts
Chrome – Full support
Chrome 120 (Release date: 2023-12-05)
footnote
footnote Available for use with Manifest V3 only.
Edge – Full support
Edge 120 (Release date: 2023-12-07)
footnote
footnote Available for use with Manifest V3 only.
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote
footnote Available for use with Manifest V3 only.
footnote An incompatible version of this API is available for Manifest V2. See userScripts (Legacy).
Opera – Full support
Opera 106 (Release date: 2023-12-19)
footnote
footnote Available for use with Manifest V3 only.
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
ExecutionWorld
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 Full support
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
RegisteredUserScript
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 Full support
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
RegisteredUserScript.worldId
Chrome – Full support
Chrome 133 (Release date: 2025-02-04)
footnote Full support
Edge – Full support
Edge 133 (Release date: 2025-02-06)
footnote Full support
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote Full support
Opera – Full support
Opera 118 (Release date: 2025-04-15)
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
ScriptSource
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 Full support
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
UserScriptFilter
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 Full support
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
WorldProperties
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 Full support
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
WorldProperties.worldId
Chrome – Full support
Chrome 133 (Release date: 2025-02-04)
footnote Full support
Edge – Full support
Edge 133 (Release date: 2025-02-06)
footnote Full support
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote Full support
Opera – Full support
Opera 118 (Release date: 2025-04-15)
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
configureWorld
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 Full support
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
execute
Chrome – Full support
Chrome 135 (Release date: 2025-04-01)
footnote Full support
Edge – Full support
Edge 135 (Release date: 2025-04-04)
footnote Full support
Firefox – No support
Firefox
footnote
footnote See bug 1930776
Opera – Full support
Opera 120 (Release date: 2025-07-02)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote
footnote See bug 1930776
Safari on iOS – No support
Safari on iOS
footnote No support
getScripts
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 Full support
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
getWorldConfigurations
Chrome – Full support
Chrome 133 (Release date: 2025-02-04)
footnote Full support
Edge – Full support
Edge 133 (Release date: 2025-02-06)
footnote Full support
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote Full support
Opera – Full support
Opera 118 (Release date: 2025-04-15)
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
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
resetWorldConfiguration
Chrome – Full support
Chrome 133 (Release date: 2025-02-04)
footnote Full support
Edge – Full support
Edge 133 (Release date: 2025-02-06)
footnote Full support
Firefox – Full support
Firefox 136 (Release date: 2025-03-04)
footnote Full support
Opera – Full support
Opera 118 (Release date: 2025-04-15)
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
unregister
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 Full support
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
update
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 Full support
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.

See also