userScripts.register()
Registers user scripts for the extension.
Syntax
js
let registeredUserScript = browser.userScripts.register(
scripts // array of objects
)
Parameters
scripts
-
array
ofuserScripts.RegisteredUserScript
. Details of user scripts to register.Each
userScripts.RegisteredUserScript
object must contain thejs
property as a non-empty array and a non-empty array in eithermatches
orincludeGlobs
.
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/*"],
},
]);