| title | scripting.updateContentScripts() |
|---|---|
| slug | Mozilla/Add-ons/WebExtensions/API/scripting/updateContentScripts |
| page-type | webextension-api-function |
| browser-compat | webextensions.api.scripting.updateContentScripts |
| sidebar | addonsidebar |
Updates registered content scripts. If there are errors during script parsing and file validation, or if the IDs specified do not exist, no scripts are updated.
Note
This method is available in Manifest V3 or higher in Chrome and Firefox 101. In Firefox 102+, this method is also available in Manifest V2.
To call this API, you must have the "scripting" permission. To run the injected script, the extension must have permission for the page's URL, either explicitly as a host permission or using the activeTab permission.
await browser.scripting.updateContentScripts(
scripts // object
)
scripts- :
arrayof {{WebExtAPIRef("scripting.RegisteredContentScript")}}. Details of a script to update. All the properties are optional except forid.
- :
A Promise that fulfills with an array of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. If any error occurs, the promise is rejected.
This example updates a content script registered with ID a-script by setting allFrames to true:
try {
await browser.scripting.registerContentScripts([
{
id: "a-script",
js: ["script.js"],
matches: ["*://example.org/*"],
},
]);
// Update content script registered before to allow execution
// in all frames:
await browser.scripting.updateContentScripts([
{
id: "a-script",
allFrames: true,
},
]);
} catch (err) {
console.error(`failed to register or update content scripts: ${err}`);
}{{WebExtExamples}}
{{Compat}}
Note
This API is based on Chromium's chrome.scripting API.