files/en-us/mozilla/add-ons/webextensions/api/scripting/getregisteredcontentscripts/index.md
Returns all the content scripts registered with {{WebExtAPIRef("scripting.registerContentScripts()")}} or a subset of the registered scripts when using a filter.
[!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 use this API you must have the "scripting" permission and permission for the page's URL, either explicitly as a host permission or using the activeTab permission.
This is an asynchronous function that returns a Promise.
let scripts = await browser.scripting.getRegisteredContentScripts(
filter // object
)
filter {{optional_inline}}
A Promise that fulfills with an array of {{WebExtAPIRef("scripting.RegisteredContentScript")}}. If any error occurs, the promise is rejected.
This example returns all the registered content scripts:
// Register two content scripts.
await browser.scripting.registerContentScripts([
{
id: "script-1",
js: ["script-1.js"],
matches: ["*://example.com/*"],
},
{
id: "script-2",
js: ["script-2.js"],
matches: ["*://example.com/*"],
},
]);
// Retrieve all content scripts.
let scripts = await browser.scripting.getRegisteredContentScripts();
console.log(scripts.map((script) => script.id)); // ["script-1", "script-2"]
// Only retrieve the second script.
scripts = await browser.scripting.getRegisteredContentScripts({
ids: ["script-2"],
});
console.log(scripts.map((script) => script.id)); // ["script-2"]
{{WebExtExamples}}
{{Compat}}
[!NOTE] This API is based on Chromium's
chrome.scriptingAPI.