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 + |
rpl
left a comment
There was a problem hiding this comment.
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).
4c42f83 to
76e6986
Compare
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.
Plural form mismatch, "its" should be "their" or use a singular for "A content script may...".
|
|
||
| #### 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.
- "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