diff --git a/files/en-us/_redirects.txt b/files/en-us/_redirects.txt index ee51a809e46ed93..472cb91f8eebfad 100644 --- a/files/en-us/_redirects.txt +++ b/files/en-us/_redirects.txt @@ -6123,7 +6123,11 @@ /en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy/registerProxyScript /en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy /en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy/unregister /en-US/docs/Mozilla/Add-ons/WebExtensions/API/proxy /en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/moveInSuccession() /en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/moveInSuccession -/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/RegisteredUserScript.unregister() /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/unregister +/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/RegisteredUserScript.unregister() /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/RegisteredUserScript/unregister +/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/unregister /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/RegisteredUserScript/unregister +/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/UserScriptOptions /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/UserScriptOptions +/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/Working_with_userScripts /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/Working_with_userScripts +/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/onBeforeScript /en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/onBeforeScript /en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows/update() /en-US/docs/Mozilla/Add-ons/WebExtensions/API/windows/update /en-US/docs/Mozilla/Add-ons/WebExtensions/Accessible_guidelines https://extensionworkshop.com/documentation/develop/build-an-accessible-extension/ /en-US/docs/Mozilla/Add-ons/WebExtensions/Add-on_ID https://extensionworkshop.com/documentation/develop/extensions-and-the-add-on-id/ diff --git a/files/en-us/_wikihistory.json b/files/en-us/_wikihistory.json index ebcb67df18cb545..0ea2aba404b972a 100644 --- a/files/en-us/_wikihistory.json +++ b/files/en-us/_wikihistory.json @@ -14426,22 +14426,6 @@ "modified": "2020-10-15T22:20:45.849Z", "contributors": ["rebloor", "irenesmith", "bershanskiy", "pesar81"] }, - "Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/unregister": { - "modified": "2020-10-15T22:22:39.367Z", - "contributors": ["rebloor", "hellosct1", "bershanskiy"] - }, - "Mozilla/Add-ons/WebExtensions/API/userScripts/UserScriptOptions": { - "modified": "2020-06-22T16:28:43.349Z", - "contributors": ["hellosct1", "MelchiorIm3Tal", "irenesmith"] - }, - "Mozilla/Add-ons/WebExtensions/API/userScripts/Working_with_userScripts": { - "modified": "2020-06-22T16:28:43.959Z", - "contributors": ["irenesmith", "hellosct1"] - }, - "Mozilla/Add-ons/WebExtensions/API/userScripts/onBeforeScript": { - "modified": "2020-10-15T22:23:14.808Z", - "contributors": ["chrisdavidmills", "rebloor", "bershanskiy"] - }, "Mozilla/Add-ons/WebExtensions/API/userScripts/register": { "modified": "2020-10-15T22:21:40.204Z", "contributors": [ @@ -14454,6 +14438,22 @@ "stoyanster" ] }, + "Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/RegisteredUserScript/unregister": { + "modified": "2020-10-15T22:22:39.367Z", + "contributors": ["rebloor", "hellosct1", "bershanskiy"] + }, + "Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/UserScriptOptions": { + "modified": "2020-06-22T16:28:43.349Z", + "contributors": ["hellosct1", "MelchiorIm3Tal", "irenesmith"] + }, + "Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/Working_with_userScripts": { + "modified": "2020-06-22T16:28:43.959Z", + "contributors": ["irenesmith", "hellosct1"] + }, + "Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/onBeforeScript": { + "modified": "2020-10-15T22:23:14.808Z", + "contributors": ["chrisdavidmills", "rebloor", "bershanskiy"] + }, "Mozilla/Add-ons/WebExtensions/API/webNavigation": { "modified": "2020-10-15T21:38:48.088Z", "contributors": ["fscholz", "wbamberg", "abbycar"] diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md index 6c2897e4a018eff..00ed59016684501 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md @@ -47,5 +47,5 @@ To use the API, call `{{WebExtAPIRef("userScripts.register","register()")}}` pas ## See also -- [Working with `userScripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/Working_with_userScripts) +- [Working with `userScripts` (Legacy)](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/Working_with_userScripts) - {{WebExtAPIRef("contentScripts","browser.contentScripts")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/unregister/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/unregister/index.md deleted file mode 100644 index e60cb516c90c61f..000000000000000 --- a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/unregister/index.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: RegisteredUserScript.unregister() -slug: Mozilla/Add-ons/WebExtensions/API/userScripts/RegisteredUserScript/unregister -page-type: webextension-api-function -browser-compat: webextensions.api.userScripts.RegisteredUserScript.unregister ---- - -{{AddonSidebar}} - -The `unregister()` method of the {{WebExtAPIRef("userScripts.RegisteredUserScript","RegisteredUserScript")}} object unregisters the user scripts represented by the object, user scripts that were registered using {{WebExtAPIRef("userScripts.register","userScripts.register()")}}. - -> [!NOTE] -> User Scripts are automatically 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. - -## Syntax - -```js-nolint -const registeredUserScript = await browser.userScripts.register( - userScriptOptions // object -); -// … -await registeredUserScript.unregister() -``` - -### Parameters - -None. - -### Return value - -A {{JSxRef("Promise")}} that is resolved once the user scripts are unregistered. The promise does not return a value. - -## Browser compatibility - -{{Compat}} - -## See also - -- {{WebExtAPIRef("userScripts.register","userScripts.register()")}} -- {{WebExtAPIRef("userScripts.RegisteredUserScript","RegisteredUserScript")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/index.md new file mode 100644 index 000000000000000..9f9bed232850087 --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/index.md @@ -0,0 +1,51 @@ +--- +title: userScripts (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy +page-type: webextension-api +browser-compat: webextensions.api.userScripts_legacy +--- + +{{AddonSidebar}} + +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + +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 {{WebExtAPIRef("contentScripts")}} but with features suited to handling third-party scripts: + +- execution is in an isolated sandbox: each user script is run in an isolated sandbox within the web content processes, preventing accidental or deliberate interference among scripts. +- access to the `window` and `document` global values related to the webpage the user script is attached to. +- no access to WebExtension APIs or associated permissions granted to the extension: the API script, which inherits the extension's permissions, can provide packaged WebExtension APIs to registered user scripts. An API script is declared in the extension's manifest file using the "user_scripts" manifest key. + +> [!WARNING] +> This API requires the presence of the [`user_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/user_scripts) key in the manifest.json, even if no API script is specified. For example. `user_scripts: {}`. + +To use the API, call `{{WebExtAPIRef("userScripts_legacy.register","register()")}}` passing in an object defining the scripts to register. The method returns a Promise that is resolved with a `{{WebExtAPIRef("userScripts_legacy.RegisteredUserScript","RegisteredUserScript")}}` object. + +> [!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. + +## Types + +- {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript", "userScripts.RegisteredUserScript")}} + - : The `object` returned by the {{WebExtAPIRef("userScripts_legacy.register","register()")}} method. It represents the registered user scripts and is used to deregister the user scripts. + +## Methods + +- {{WebExtAPIRef("userScripts_legacy.register", "userScripts.register()")}} + - : Registers user scripts. + +## Events + +- {{WebExtAPIRef("userScripts_legacy.onBeforeScript", "userScripts.onBeforeScript")}} + - : An event available to the API script, registered in [`"user_scripts"`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/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. + +## Browser compatibility + +{{Compat}} + +## See also + +- [Working with `userScripts` (Legacy)](/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/Working_with_userScripts) +- {{WebExtAPIRef("contentScripts","browser.contentScripts")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/onbeforescript/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/onbeforescript/index.md similarity index 80% rename from files/en-us/mozilla/add-ons/webextensions/api/userscripts/onbeforescript/index.md rename to files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/onbeforescript/index.md index 4eec81e52b022a7..9d294d2cba3b33e 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/onbeforescript/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/onbeforescript/index.md @@ -1,13 +1,16 @@ --- -title: userScripts.onBeforeScript -slug: Mozilla/Add-ons/WebExtensions/API/userScripts/onBeforeScript +title: userScripts.onBeforeScript (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/onBeforeScript page-type: webextension-api-event -browser-compat: webextensions.api.userScripts.onBeforeScript +browser-compat: webextensions.api.userScripts_legacy.onBeforeScript --- {{AddonSidebar}} -The `onBeforeScript` event of the {{WebExtAPIRef("userScripts","browser.userScripts")}} is fired before a user script is executed. It can only be included in the API script, the script registered in [`"user_scripts"`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/user_scripts), where it is used to detect that the custom API methods should be exported to the user script. +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + +The `onBeforeScript` event of the {{WebExtAPIRef("userScripts_legacy","browser.userScripts")}} is fired before a user script is executed. It can only be included in the API script, the script registered in [`"user_scripts"`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/user_scripts), where it is used to detect that the custom API methods should be exported to the user script. ## Syntax diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/register/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/register/index.md new file mode 100644 index 000000000000000..c8c669655d5ceff --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/register/index.md @@ -0,0 +1,75 @@ +--- +title: userScripts.register() (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/register +page-type: webextension-api-function +browser-compat: webextensions.api.userScripts_legacy.register +--- + +{{AddonSidebar}} + +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + +This method enables user scripts to be registered from an extension's pages (such as the background page). + +This method is very similar to the {{WebExtAPIRef("contentScripts.register","contentScripts.register()")}} API method (for example, they both return a promise that resolves to an API object with an {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript.unregister","unregister()")}} method for unregistering the script). There are, however, differences in the options supported. + +This is an asynchronous method that returns a {{JSxRef("Promise")}}. + +## Syntax + +```js-nolint +const registeredUserScript = await browser.userScripts.register( + userScriptOptions // object +); +// … +await registeredUserScript.unregister(); +``` + +### Parameters + +- `userScriptOptions` + + - : `object`. Represents the user scripts to register. It has similar syntax to {{WebExtAPIRef("contentScripts.register","contentScripts.register()")}}. + + The `UserScriptOptions` object has the following properties: + + - `scriptMetadata` {{Optional_Inline}} + - : A `JSON` object containing arbitrary metadata properties associated with the registered user scripts. However, while arbitrary, the object must be serializable, so it is compatible with [the structured clone algorithm.](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) This metadata is used to pass details from the script to the [API script](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/user_scripts). For example, providing details of a subset of the APIs that need to be injected by the [API script](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/user_scripts). The API does not use this metadata, + - `allFrames` {{Optional_Inline}} + - : Same as `all_frames` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + - `cookieStoreId` {{optional_inline}} + - : An array of cookie store ID strings or a string containing a cookie store ID. Registers the user script in the tabs that belong to the cookie store IDs. This enables scripts to be registered for all default or non-contextual identity tabs, private browsing tabs (if the [extension is enabled in private browsing](https://support.mozilla.org/en-US/kb/extensions-private-browsing)), the tabs of a [contextual identity](/en-US/docs/Mozilla/Add-ons/WebExtensions/Work_with_contextual_identities), or a combination of these. + - `excludeGlobs` {{Optional_Inline}} + - : Same as `exclude_globs` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + - `excludeMatches` {{Optional_Inline}} + - : Same as `exclude_matches` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + - `includeGlobs` {{Optional_Inline}} + - : Same as `include_globs` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + - `js` + - : An array of objects. Each object has either a property named `file`, which is a URL starting at the extension's manifest.json and pointing to a JavaScript file to register, or a property named `code`, which contains JavaScript code to register. + - `matchAboutBlank` {{Optional_Inline}} + - : Same as `match_about_blank` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + - `matches` + - : Same as `matches` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + The URL patterns provided in `matches` must be enabled by the host permissions defined in the manifest [`permission`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions) property or enabled by the user from the [`optional_permissions`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/optional_permissions) list. For example, if matches includes `https://mozilla.org/a` a script is only registered if host permissions include, for example, `https://mozilla.org/*`. If the URL pattern isn't enabled, the call to register fails with the error "Permission denied to register a user script for ORIGIN". + - `runAt` {{Optional_Inline}} + - : Same as `run_at` in the [`content_scripts`](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts) key. + +Unlike content script options, the userScriptOptions object does not have a CSS property. Use {{WebExtAPIRef("contentScripts.register","contentScripts.register()")}} to dynamically register and unregister stylesheets. + +### Return value + +A {{JSxRef("Promise")}} that is fulfilled with a {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript","RegisteredUserScript")}} object that is use to unregister the user scripts. + +> [!NOTE] +> User scripts are unregistered when the related extension page (from which the user scripts were registered) is unloaded, so you should register user scripts from an extension page that persists at least as long as you want the user scripts to stay registered. + +## Browser compatibility + +{{Compat}} + +## See also + +- {{WebExtAPIRef("contentScripts.register","contentScripts.register()")}} +- {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript.unregister","RegisteredUserScript.unregister()")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/index.md new file mode 100644 index 000000000000000..69a29af16e3e4fe --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/index.md @@ -0,0 +1,27 @@ +--- +title: userScripts.RegisteredUserScript (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/RegisteredUserScript +page-type: webextension-api-type +browser-compat: webextensions.api.userScripts_legacy.RegisteredUserScript +--- + +{{AddonSidebar}} + +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + +A `RegisteredUserScript` object is returned by a call to {{WebExtAPIRef("userScripts_legacy.register","userScripts.register()")}} and represents the user scripts registered in that call. + +The object defines a single method, {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript.unregister","unregister()")}}, which is used to unregister the user scripts. + +> [!NOTE] +> If this object is destroyed (for example because it goes out of scope) then the associated scripts will be unregistered automatically, so you should keep a reference to this object for as long as you want the user scripts to stay registered. + +## Methods + +- {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript.unregister","unregister()")}} + - : Unregisters the user scripts represented by this object. + +## Browser compatibility + +{{Compat}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/unregister/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/unregister/index.md new file mode 100644 index 000000000000000..01b5f6ee6e7daaa --- /dev/null +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/registereduserscript/unregister/index.md @@ -0,0 +1,43 @@ +--- +title: RegisteredUserScript.unregister() (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/RegisteredUserScript/unregister +page-type: webextension-api-function +browser-compat: webextensions.api.userScripts_legacy.RegisteredUserScript.unregister +--- + +{{AddonSidebar}} + +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + +The `unregister()` method of the {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript","RegisteredUserScript")}} object unregisters the user scripts represented by the object, user scripts that were registered using {{WebExtAPIRef("userScripts_legacy.register","userScripts.register()")}}. + +> [!NOTE] +> User Scripts are automatically 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. + +## Syntax + +```js-nolint +const registeredUserScript = await browser.userScripts.register( + userScriptOptions // object +); +// … +await registeredUserScript.unregister() +``` + +### Parameters + +None. + +### Return value + +A {{JSxRef("Promise")}} that is resolved once the user scripts are unregistered. The promise does not return a value. + +## Browser compatibility + +{{Compat}} + +## See also + +- {{WebExtAPIRef("userScripts_legacy.register","userScripts.register()")}} +- {{WebExtAPIRef("userScripts_legacy.RegisteredUserScript","RegisteredUserScript")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/userscriptoptions/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/userscriptoptions/index.md similarity index 86% rename from files/en-us/mozilla/add-ons/webextensions/api/userscripts/userscriptoptions/index.md rename to files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/userscriptoptions/index.md index 1d1f3c8e9ac7139..8a8fa9ac72e1783 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/userscriptoptions/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/userscriptoptions/index.md @@ -1,11 +1,14 @@ --- -title: UserScripts.UserScriptOptions -slug: Mozilla/Add-ons/WebExtensions/API/userScripts/UserScriptOptions +title: UserScripts.UserScriptOptions (Legacy) +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/UserScriptOptions page-type: webextension-api-type --- {{AddonSidebar}} +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + The UserScriptOptions object represents the content scripts to register. It has similar syntax to the contentScript options supported by browser.contentScripts.register. The differences are: - it does not support a CSS property (use browser.contentScripts.register to dynamically register/unregister stylesheets) diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/index.md b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/index.md similarity index 89% rename from files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/index.md rename to files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/index.md index 77589718aea64c6..d384e775e576f22 100644 --- a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/index.md @@ -1,11 +1,14 @@ --- title: Working with userScripts -slug: Mozilla/Add-ons/WebExtensions/API/userScripts/Working_with_userScripts +slug: Mozilla/Add-ons/WebExtensions/API/userScripts_legacy/Working_with_userScripts page-type: guide --- {{AddonSidebar}} +> [!WARNING] +> This is documentation for the legacy `userScripts` API. It's available in Firefox for Manifest V2. For functionality to work with user scripts in Manifest V3 see the new {{WebExtAPIRef("userScripts")}} API. + By implementing userScripts, extension developers can modify how sites look and/or work to better meet user needs. Implement userScripts in your extension using the following steps: @@ -103,6 +106,6 @@ Once the script has been registered, navigate to a page whose domain name ends i ## See also -- {{WebExtAPIRef("userScripts")}} -- {{WebExtAPIRef("userScripts.register()", "userScripts.register()")}} -- {{WebExtAPIRef("userScripts.onBeforeScript")}} +- {{WebExtAPIRef("userScripts_legacy","userScripts")}} +- {{WebExtAPIRef("userScripts_legacy.register()", "userScripts.register()")}} +- {{WebExtAPIRef("userScripts_legacy.onBeforeScript")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/user_script_in_action.png b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/user_script_in_action.png similarity index 100% rename from files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/user_script_in_action.png rename to files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/user_script_in_action.png diff --git a/files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/userscriptexample.png b/files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/userscriptexample.png similarity index 100% rename from files/en-us/mozilla/add-ons/webextensions/api/userscripts/working_with_userscripts/userscriptexample.png rename to files/en-us/mozilla/add-ons/webextensions/api/userscripts_legacy/working_with_userscripts/userscriptexample.png diff --git a/files/en-us/mozilla/add-ons/webextensions/manifest.json/user_scripts/index.md b/files/en-us/mozilla/add-ons/webextensions/manifest.json/user_scripts/index.md index edcf2620485ff63..c14295806eced9c 100644 --- a/files/en-us/mozilla/add-ons/webextensions/manifest.json/user_scripts/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/manifest.json/user_scripts/index.md @@ -7,6 +7,9 @@ browser-compat: webextensions.manifest.user_scripts {{AddonSidebar}} +> [!WARNING] +> This key is used by the legacy {{WebExtAPIRef("userScripts_legacy","userScripts")}} API, which is available to extensions using Manifest V2. This key is not required for the version of the {{WebExtAPIRef("userScripts","userScripts")}} API available for use with Manifest V3. + @@ -38,7 +41,7 @@ browser-compat: webextensions.manifest.user_scripts Instructs the browser to load a script packaged in the extension, known as the API script, this script is used to export a set of custom API methods for use in user scripts. The API script path, relative to the manifest.json file, is defined as a `string` in `"api_script"`. > [!NOTE] -> The `user_script` key is required for the {{WebExtAPIRef("userScripts")}} API to function, even if no API script is specified. For example. `user_scripts: {}`. +> The `user_script` key is required for the {{WebExtAPIRef("userScripts_legacy","userScripts")}} API to function, even if no API script is specified. For example. `user_scripts: {}`. The API script: @@ -46,11 +49,11 @@ The API script: - has access to the window and document globals related to the webpage it is attached to. - has access to the same subset of WebExtension APIs usually available in a content script. -The script executes automatically on any webpage defined in `matches` by {{WebExtAPIRef("userScripts.register")}}. However, this is before the user script sandbox object is created and the custom API methods can be exported. +The script executes automatically on any webpage defined in `matches` by {{WebExtAPIRef("userScripts_legacy.register", "userScripts.register()")}}. However, this is before the user script sandbox object is created and the custom API methods can be exported. -To export the custom API methods, the script listens for {{WebExtAPIRef("userScripts.onBeforeScript")}} and then export the custom API methods. +To export the custom API methods, the script listens for {{WebExtAPIRef("userScripts_legacy.onBeforeScript", "userScripts.onBeforeScript")}} and then export the custom API methods. -Not every user script may need to consume all of the custom API methods. You can, therefore, include details of the APIs needed in `scriptMetadata` when running {{WebExtAPIRef("userScripts.register")}}. The API script then accesses the `scriptMetadata` through the `script` parameter received by the {{WebExtAPIRef("userScripts.onBeforeScript")}} listener (as `script.metadata`). +Not every user script may need to consume all of the custom API methods. You can, therefore, include details of the APIs needed in `scriptMetadata` when running {{WebExtAPIRef("userScripts_legacy.register", "userScripts.register()")}}. The API script then accesses the `scriptMetadata` through the `script` parameter received by the {{WebExtAPIRef("userScripts_legacy.onBeforeScript", "userScripts.onBeforeScript")}} listener (as `script.metadata`). ## Browser compatibility @@ -58,5 +61,5 @@ Not every user script may need to consume all of the custom API methods. You can ## See also -- {{WebExtAPIRef("userScripts")}} +- {{WebExtAPIRef("userScripts_legacy","userScripts")}} (Legacy) - {{WebExtAPIRef("contentScripts")}} diff --git a/files/en-us/mozilla/add-ons/webextensions/work_with_contextual_identities/index.md b/files/en-us/mozilla/add-ons/webextensions/work_with_contextual_identities/index.md index 10aa2b942bdf7ab..11967061d4abf68 100644 --- a/files/en-us/mozilla/add-ons/webextensions/work_with_contextual_identities/index.md +++ b/files/en-us/mozilla/add-ons/webextensions/work_with_contextual_identities/index.md @@ -33,7 +33,7 @@ Several extension APIs include the `cookieStoreId` in objects to enable extensio - {{WebExtAPIRef("downloads")}} where you can associate a download with a cookie store. - {{WebExtAPIRef("proxy")}} where the details passed into the {{WebExtAPIRef("proxy.onRequest")}} listener identify the cookie store associated with the request. - {{WebExtAPIRef("tabs")}} where you can {{WebExtAPIRef("tabs.create","create")}} a tab in a container tab, {{WebExtAPIRef("tabs.tab","get")}} the `cookieStoreId` for a tab, and {{WebExtAPIRef("tabs.query","query")}} tabs based on their associated cookie store. -- {{WebExtAPIRef("userScripts.register")}} enables you to register a content script restricted to documents associated with one or more `cookieStoreIds`. +- {{WebExtAPIRef("userScripts_legacy.register","userScripts.register()")}} (legacy version, Manifest V2 only) enables you to register a content script restricted to documents associated with one or more `cookieStoreIds`. - {{WebExtAPIRef("webRequest")}} where all the events return the `cookieStoreId` of the request. - {{WebExtAPIRef("windows.create")}} where you can specify the cookie store for the tabs added to a window when it's created.