Skip to content

userScripts documentation fixups#38348

Merged
Rob--W merged 6 commits intomdn:mainfrom
Rob--W:userScripts-fixups
Mar 4, 2025
Merged

userScripts documentation fixups#38348
Rob--W merged 6 commits intomdn:mainfrom
Rob--W:userScripts-fixups

Conversation

@Rob--W
Copy link
Copy Markdown
Member

@Rob--W Rob--W commented Feb 26, 2025

Description

  • 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"

Motivation

Fix inaccuracies and improve discovery of relevant information.

Additional details

Related issues and pull requests

Follow-up to #38073.

- 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"
@Rob--W Rob--W added the Content:WebExt WebExtensions docs label Feb 26, 2025
@Rob--W Rob--W requested a review from rebloor February 26, 2025 20:54
@Rob--W Rob--W requested a review from a team as a code owner February 26, 2025 20:54
@github-actions github-actions bot added the size/s [PR only] 6-50 LoC changed label Feb 26, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 26, 2025

Copy link
Copy Markdown
Contributor

@rebloor rebloor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rob--W A couple of suggestions for you to consider.

Comment on lines 26 to +32
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.

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()")}}.
User scripts can share the same world, but they can also be isolated from each other by declaring separate `USER_SCRIPT` worlds through the `worldId` property of a {{WebExtAPIRef("userScripts.RegisteredUserScript", "RegisteredUserScript")}}. The API also enables an extension to configure a content security policy (CSP) for the `USER_SCRIPT` world using {{WebExtAPIRef("userScripts.configureWorld()")}}.

In the `MAIN` world, host pages and other extensions can see and access running user scripts.
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.

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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
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()")}}.
User scripts can share the same world, but they can also be isolated from each other by declaring separate `USER_SCRIPT` worlds through the `worldId` property of a {{WebExtAPIRef("userScripts.RegisteredUserScript", "RegisteredUserScript")}}. The API also enables an extension to configure a content security policy (CSP) for the `USER_SCRIPT` world using {{WebExtAPIRef("userScripts.configureWorld()")}}.
In the `MAIN` world, host pages and other extensions can see and access running user scripts.
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.
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.
There are two types of world for your extension to run user scripts in:
- `MAIN` world. In this world, host pages and other extensions can see and access the running user scripts. There is only one `MAIN` world that can run one or more user script.
- `USER_SCRIPT` worlds. These are isolated worlds where user scripts aren't visible to the host page or other extensions' user and content scripts. Similarly, user script in one `USER_SCRIPT` world can't see or access user scripts in another `USER_SCRIPT` world. Each `USER_SCRIPT` world can run one or more user scripts.
`USER_SCRIPT` worlds are created by setting the `worldId` property of {{WebExtAPIRef("userScripts.RegisteredUserScript", "RegisteredUserScript")}} when registering or updating a user script. The API also enables an extension to configure a content security policy (CSP) for a `USER_SCRIPT` world using {{WebExtAPIRef("userScripts.configureWorld()")}}.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "USER_SCRIPT worlds are created by setting the worldId property" bit is inaccurate. What worldId does is allowing for separate/multiple USER_SCRIPT worlds to be specified. It can be omitted to still have the (default) USER_SCRIPT world.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggested text does not convey the intended meaning; To avoid unnecessary delays in documentation I'm going to merge this PR. Feel free to submit a new PR to improve the wording if you'd like.

…dproperties/index.md

Co-authored-by: rebloor <git@sherpa.co.nz>
Copy link
Copy Markdown
Contributor

@rebloor rebloor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rob--W tidy up suggestions only

Comment thread files/en-us/mozilla/add-ons/webextensions/api/userscripts/index.md Outdated
User scripts can share the same world, but they can also be isolated from each other by declaring separate `USER_SCRIPT` worlds through the `worldId` property of a {{WebExtAPIRef("userScripts.RegisteredUserScript", "RegisteredUserScript")}}. The API also enables an extension to configure a content security policy (CSP) for the `USER_SCRIPT` world using {{WebExtAPIRef("userScripts.configureWorld()")}}.

In the `MAIN` world, host pages and other extensions can see and access running user scripts.
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.
Copy link
Copy Markdown
Contributor

@rebloor rebloor Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
A `USER_SCRIPT` world provides an isolated execution environment that isn't accessible to the host page or other extensions. This means a user script:
- isn't visible to and
- can change its JavaScript environment without affecting
the host page or other extensions' user and content scripts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This proposed text doesn't look very readable, "isn't visible to and" looks strange.

I think that a follow-up improvement could be to just cut most of the text and refer to https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/userScripts/ExecutionWorld instead for a longer description

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to avoid readability issues created by two apparently very similar sentences. How about this?

Suggested change
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.
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 and isn't visible to its host page or other extensions' user and content scripts.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about this? And maybe switch up with the previous paragraph?

Suggested change
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.
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.

@Rob--W Rob--W merged commit 3d283cb into mdn:main Mar 4, 2025
estelle pushed a commit that referenced this pull request Mar 5, 2025
* 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>
cssinate pushed a commit to cssinate/content that referenced this pull request Apr 11, 2025
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:WebExt WebExtensions docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants