userScripts.update()

Updates user scripts registered by the extension.

Syntax

js
let updatingUserScript = browser.userScripts.update(
  scripts       // array of objects
);

Parameters

scripts

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

Properties that are null or omitted are not changed. Passing an empty array to matches, excludeMatches, globs, and excludeGlobs clears these properties.

Return value

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

Examples

This snippet shows two examples of updates to a user scripts. The first update fails because it attempts to create an invalid script registration. The second example shows a successful update.

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

// Invalid! Would result in script without matches or includeGlobs!
await browser.userScripts.update([{ matches: [] }]);

// Valid: replaces matches with includeGlobs.
await browser.userScripts.update([
  {
    matches: [],
    includeGlobs: ["*example*"],
  },
]);

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
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