Skip to content

Commit 3d283cb

Browse files
Rob--Wrebloor
andauthored
userScripts documentation fixups (mdn#38348)
* 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>
1 parent 15be229 commit 3d283cb

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@ To use this API, you need the `userScripts` permission and [`host_permissions`](
2525

2626
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.
2727

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.
2929

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.
3133

3234
These execution world values are defined in {{WebExtAPIRef("userScripts.ExecutionWorld","ExecutionWorld")}}.
3335

@@ -47,9 +49,6 @@ browser.userScripts.configureWorld({
4749

4850
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.
4951

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-
5352
## Types
5453

5554
- {{WebExtAPIRef("userScripts.ExecutionWorld")}}
@@ -81,6 +80,8 @@ When an extension updates, user scripts are cleared. To restore scripts, add cod
8180
- {{WebExtAPIRef("userScripts.update()")}}
8281
- : Updates user scripts registered by the extension.
8382

83+
{{WebExtExamples("h2")}}
84+
8485
## Browser compatibility
8586

8687
{{Compat}}

files/en-us/mozilla/add-ons/webextensions/api/userscripts/registereduserscript/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ browser-compat: webextensions.api.userScripts.RegisteredUserScript
77

88
{{AddonSidebar}}
99

10-
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()")}}.
1111

1212
## Type
1313

@@ -24,9 +24,9 @@ Values of this type are an object containing these properties:
2424
- `excludeMatches` {{optional_inline}}
2525
- : `array` of `string`. [Match patterns](/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns) for pages that the script must not be run in.
2626
- `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.
2828
- `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.
3030
- `runAt` {{optional_inline}}
3131
- : {{WebExtAPIRef("extensionTypes.RunAt")}}. The earliest the script is injected into a tab. Defaults to `"document_idle"`.
3232
- `world` {{optional_inline}}

files/en-us/mozilla/add-ons/webextensions/api/userscripts/worldproperties/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The configuration of a `USER_SCRIPT` execution environment. Used in {{WebExtAPIR
1414
Values of this type are an object containing these properties:
1515

1616
- `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.
1818
- `csp` {{optional_inline}}
1919
- : `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()`.
2020
- `messaging` {{optional_inline}}

0 commit comments

Comments
 (0)