You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* userScripts documentation fixups
- Add WebExtExamples to main userScripts article
- Clarify execution world behavior.
- Remove incorrect note about user script unregistration.
- Add more cross-references, such as a link to "Glob pattern"
* Update files/en-us/mozilla/add-ons/webextensions/api/userscripts/worldproperties/index.md
Co-authored-by: rebloor <git@sherpa.co.nz>
* Update files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md
Co-authored-by: rebloor <git@sherpa.co.nz>
* USW isolation para update
* Swappimg paras and correctly applying Robs suggestion
---------
Co-authored-by: rebloor <git@sherpa.co.nz>
Copy file name to clipboardExpand all lines: files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md
+6-5Lines changed: 6 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,9 +25,11 @@ To use this API, you need the `userScripts` permission and [`host_permissions`](
25
25
26
26
When a user script is registered or updated (using {{WebExtAPIRef("userScripts.register()")}} or {{WebExtAPIRef("userScripts.update()")}}), your extension can set it to run in an isolated `USER_SCRIPT` world or the `MAIN` world.
27
27
28
-
A `USER_SCRIPT` world provides an isolated execution environment that isn't accessible to a host page or other extensions. This means a user script can change its JavaScript environment without affecting the host page or other extensions' user and content scripts. In this environment, user scripts aren't visible to the host page or other extensions' user and content scripts. The API also enables an extension to configure a content security policy (CSP) for the `USER_SCRIPT`world using {{WebExtAPIRef("userScripts.configureWorld()")}}.
28
+
A `USER_SCRIPT` world provides an isolated execution environment that isn't accessible to a host page or other extensions. This isolation is similar to a [content script environment](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#content_script_environment), except `USER_SCRIPT`worlds cannot access extension APIs.
29
29
30
-
In the `MAIN` world, host pages and other extensions can see and access running user scripts.
30
+
User scripts can share a `USER_SCRIPT` world or isolate themselves in a `USER_SCRIPT` world by setting the `worldId` property of {{WebExtAPIRef("userScripts.RegisteredUserScript", "RegisteredUserScript")}}. The API enables an extension to configure a content security policy (CSP) for a `USER_SCRIPT` world using {{WebExtAPIRef("userScripts.configureWorld()")}}.
31
+
32
+
In the `MAIN` world, host pages and other extensions can see and access running user scripts. The `worldId` property is not supported for `MAIN` worlds.
31
33
32
34
These execution world values are defined in {{WebExtAPIRef("userScripts.ExecutionWorld","ExecutionWorld")}}.
When an extension updates, user scripts are cleared. To restore scripts, add code to the extension's {{WebExtAPIRef("runtime.onInstalled")}} event handler that responds to the `"update"` reason.
49
51
50
-
> [!NOTE]
51
-
> User scripts are unregistered when the related extension page (from which the user scripts were registered) is unloaded, so register user scripts from an extension page that persists as long as you want the user scripts to stay registered.
52
-
53
52
## Types
54
53
55
54
- {{WebExtAPIRef("userScripts.ExecutionWorld")}}
@@ -81,6 +80,8 @@ When an extension updates, user scripts are cleared. To restore scripts, add cod
81
80
- {{WebExtAPIRef("userScripts.update()")}}
82
81
- : Updates user scripts registered by the extension.
An object representing registered user scripts. Returned by {{WebExtAPIRef("userScripts.getScripts","getScripts()")}} and used as input to {{WebExtAPIRef("userScripts.register","register()")}} and {{WebExtAPIRef("userScripts.update","update()")}}.
10
+
An object representing registered user scripts. Returned by {{WebExtAPIRef("userScripts.getScripts","userScripts.getScripts()")}} and used as input to {{WebExtAPIRef("userScripts.register","userScripts.register()")}} and {{WebExtAPIRef("userScripts.update","userScripts.update()")}}.
11
11
12
12
## Type
13
13
@@ -24,9 +24,9 @@ Values of this type are an object containing these properties:
24
24
-`excludeMatches` {{optional_inline}}
25
25
- : `array` of `string`. [Match patterns](/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns) for pages that the script must not be run in.
26
26
-`includeGlobs` {{optional_inline}}
27
-
- : `string`. Glob patterns for the pages to run the script in. `matches` or `includeGlobs` must be specified in {{WebExtAPIRef("userScripts.register()")}} calls.
27
+
- : `string`. [Glob patterns](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts#globs) for the pages to run the script in. `matches` or `includeGlobs` must be specified in {{WebExtAPIRef("userScripts.register()")}} calls.
28
28
-`excludeGlobs` {{optional_inline}}
29
-
- : `string`. Glob patterns for pages that the script must not be run in.
29
+
- : `string`. [Glob patterns](/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts#globs) for pages that the script must not be run in.
30
30
-`runAt` {{optional_inline}}
31
31
- : {{WebExtAPIRef("extensionTypes.RunAt")}}. The earliest the script is injected into a tab. Defaults to `"document_idle"`.
Copy file name to clipboardExpand all lines: files/en-us/mozilla/add-ons/webextensions/api/userscripts/worldproperties/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ The configuration of a `USER_SCRIPT` execution environment. Used in {{WebExtAPIR
14
14
Values of this type are an object containing these properties:
15
15
16
16
-`worldId` {{optional_inline}}
17
-
- : `string`. The identifier for the world. Values with leading underscores (`_`) are reserved. The maximum length is 256 characters. Defaults to the default `USER_SCRIPT` world ("").
17
+
- : `string`. The identifier for the world. Values with leading underscores (`_`) are reserved. The maximum length is 256 characters. Defaults to the default `USER_SCRIPT` world (""). To run a user script in this world, pass this value as the `worldId` property in {{WebExtAPIRef("userScripts.RegisteredUserScript")}} when registering or updating a user script.
18
18
-`csp` {{optional_inline}}
19
19
- : `string`. The world's Content Security Policy (CSP). Defaults to the [default CSP for content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_Security_Policy#csp_for_content_scripts), which prohibits dynamic code execution, such as `eval()`.
0 commit comments