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.
This API offers similar capabilities to contentScripts
but with features suited to handling third-party scripts:
window
and document
global values related to the webpage the user script is attached to.Warning: This API requires the presence of the user_scripts
key in the manifest.json, even if no API script is specified. For example. user_scripts: {}
.
To use the API, call
passing in an object defining the scripts to register. The method returns a Promise that is resolved with a register()
object.RegisteredUserScript
Note: User scripts are unregistered when the related extension page (from which the user scripts were registered) is unloaded, so you should register a user script from an extension page that persists at least as long as you want the user scripts to stay registered.
userScripts.RegisteredUserScript
object
returned by the register()
method. It represents the registered user scripts and is used to deregister the user scripts.userScripts.register()
userScripts.onBeforeScript
"user_scripts"
, that execute before a user script executes. Use it to trigger the export of the additional APIs provided by the API script, so they are available to the user script.Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
RegisteredUserScript |
No |
No |
68
66
|
? |
No |
No |
? |
? |
68 |
? |
? |
? |
onBeforeScript |
No |
No |
68
66
|
? |
No |
No |
? |
? |
68 |
? |
? |
? |
register |
No |
No |
68
66
|
? |
No |
No |
? |
? |
68 |
? |
? |
? |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts