-
Notifications
You must be signed in to change notification settings - Fork 22.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document composition of content script global #24215
Conversation
Preview URLs
External URLs (1)URL:
(comment last updated: 2023-02-14 13:33:18) |
The use case is not about confusion: // trap it once and fail forever after
const {setTimeout} = window;
// VS
// works because ... developers are confused?
const setTimeout = window.setTimeout.bind(window); It is not possible to extract once like in any other JS env so it should be clarified why is that, imho. |
This proves my point. const setTimeout = globalThis.setTimeout.bind(globalThis); |
There should be zero need to bind global utilities though + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good from my perspective, the followings two comments feel just nits, the one about removing the bugzilla issue linked in this patch in also a nit but also something that I'd like to be handled before this is going to be merged).
files/en-us/mozilla/add-ons/webextensions/chrome_incompatibilities/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/content_scripts/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/chrome_incompatibilities/index.md
Outdated
Show resolved
Hide resolved
4c42f83
to
76e6986
Compare
files/en-us/mozilla/add-ons/webextensions/chrome_incompatibilities/index.md
Show resolved
Hide resolved
Related bugs: - https://bugzilla.mozilla.org/show_bug.cgi?id=1208775 (and linked bugs) - https://bugzilla.mozilla.org/show_bug.cgi?id=1288284
76e6986
to
5eb55e0
Compare
As noted at ["Content script environment" at Chrome incompatibilities](/en-US/docs/Mozilla/Add-ons/WebExtensions/Chrome_incompatibilities#content_script_environment), the behavior differs across browsers: | ||
|
||
- In Firefox, this behavior is called [Xray vision](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#xray_vision_in_firefox). | ||
Content scripts may encounter JavaScript objects from its own global scope or Xray-wrapped versions from the web page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plural form mismatch, "its" should be "their" or use a singular for "A content script may...".
@@ -197,6 +197,16 @@ When calling `tabs.remove()`: | |||
- **In Firefox:** When a content script makes an HTTP(S) request, you _must_ provide absolute URLs. | |||
- **In Chrome:** When a content script makes a request (for example, using [`fetch()`](/en-US/docs/Web/API/Fetch_API/Using_Fetch)) to a relative URL (like `/api`), it will be sent to `https://example.com/api`. | |||
|
|||
#### Content script environment | |||
|
|||
- **In Firefox:** The global scope of the [content script environment](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#content_script_environment) is not strictly equal to `window` ({{bug(1208775)}}). More specifically, the global scope (`globalThis`) is composed of standard JavaScript features as usual, plus `window` as the prototype of the global scope. Most DOM APIs are inherit from the page through `window`, through [Xray vision](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#xray_vision_in_firefox) to shield the content script from modifications by the web page. Content scripts may encounter JavaScript objects from its own global scope or Xray-wrapped versions from the web page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- "are inherited" (missing a passive "ed")
- two "through" in succession is somewhat confusing to me, maybe switch the second one to "using"
Description
Documents the composition of the content script global.
Motivation
Content scripts in extensions behave somewhat consistently across browsers, except when they don't. This is currently not clearly documented, and occasionally confuses extension developers.
Additional details
Related bugs:
Examples of bugs showing confusion from extension developers:
Related issues and pull requests
None