Bug-2017797 changes to structuredClone behavior#43539
Bug-2017797 changes to structuredClone behavior#43539
structuredClone behavior#43539Conversation
|
Preview URLs (5 pages)
Flaws (6) Note! 1 document with no flaws that don't need to be listed. 🎉 Found an unexpected or unresolvable flaw? Please report it here. URL:
URL:
URL:
URL:
(comment last updated: 2026-03-24 23:07:32) |
Rob--W
left a comment
There was a problem hiding this comment.
Firefox 149 release notes article should also mention the web facing change and the introduction of the separate window.structuredClone method in content scripts as called out in https://bugzilla.mozilla.org/show_bug.cgi?id=2017797#c39
In this PR I also added a TODO to expand on the documentation in the sharing with page article; if you anticipate that to need multiple rounds of reviews, please stick a placeholder there, so we can merge this PR ASAP and iterate on the article in a follow-up. I want the release notes updated because Firefox 149 is getting released today.
files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/content_scripts/cloneinto/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/sharing_objects_with_page_scripts/index.md
Show resolved
Hide resolved
Co-authored-by: Rob Wu <rob@robwu.nl>
…changes-to-structuredClone-behavior
structuredClone section in sharing objects article Grammar changes
files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Rob--W
left a comment
There was a problem hiding this comment.
That is a solid basis for the content, thanks. I have offered various suggestions to improve the content. Please apply them, adjust the language if needed and request review again.
| - [`exportFunction()`](#exportfunction): export a function to page scripts. | ||
| - [`cloneInto()`](#cloneinto): export an object to page scripts. | ||
| - constructors from the page context | ||
| - [`window.structuredClone()`](#structuredclone): an alternative to `cloneInto` in some cases. |
There was a problem hiding this comment.
In my previous suggestion I formatted the link in a special way so that it is obvious that it is not a regular link to the API reference, because there is a clear difference between structuredClone and window.structuredClone.
files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/index.md
Outdated
Show resolved
Hide resolved
files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/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/sharing_objects_with_page_scripts/index.md
Show resolved
Hide resolved
Co-authored-by: Rob Wu <rob@robwu.nl>
Various small edits
|
|
||
| > [!NOTE] | ||
| > In Firefox 148 and earlier, `window.structuredClone(value)` creates values in the scope of the caller instead of the window's scope. Use [`cloneInto()`](#cloneinto) if you want to support Firefox 148 and earlier. | ||
| > |
There was a problem hiding this comment.
This whole section should not be part of a quote (>). Please remove that.
(I am not adding a suggested edit because the three backticks in the end would be lost by github)
| - Adds support for `tabId` as a top-level parameter in {{WebExtAPIRef("action.isEnabled")}} and {{WebExtAPIRef("browserAction.isEnabled")}}. This change provides for compatibility with the Chrome implementation of `action.isEnabled`. ([Firefox bug 2013477](https://bugzil.la/2013477)) | ||
| - A user gesture is no longer required for {{WebExtAPIRef("action.openPopup")}} and {{WebExtAPIRef("browserAction.openPopup")}} to open a popup. This feature was available behind the `extensions.openPopupWithoutUserGesture.enabled` preference from Firefox 108. This change aligns Firefox's behavior with Chrome and Safari. ([Firefox bug 1799344](https://bugzil.la/1799344)) | ||
| - If `windowId` is passed in {{WebExtAPIRef("action.openPopup")}} or {{WebExtAPIRef("browserAction.openPopup")}}, the window must be focused (active) for the popup to open. To open a popup in an unfocused window {{WebExtAPIRef("windows.update","windows.update(windowId, { focused: true })")}} must be called first. This change aligns Firefox behavior with Chrome. ([Firefox bug 2011516](https://bugzil.la/2011516)) | ||
| - The implementation of {{domxref("structuredClone")}} has changed to instantiate objects in the `this` realm instead of the caller's realm. For backwards compatibility, the global scope of content scripts now have its own `structuredClone` method to continue allowing extensions to clone values in the content script's realm by default. This method shadows the `window.structuredClone` method, which remains available to allow extensions to clone values into the realm of the web page. For more information, see [`structuredClone` at Sharing objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). |
There was a problem hiding this comment.
have -> has (reviewing my own text and spotting typos - I am far from perfect!)
| - The implementation of {{domxref("structuredClone")}} has changed to instantiate objects in the `this` realm instead of the caller's realm. For backwards compatibility, the global scope of content scripts now have its own `structuredClone` method to continue allowing extensions to clone values in the content script's realm by default. This method shadows the `window.structuredClone` method, which remains available to allow extensions to clone values into the realm of the web page. For more information, see [`structuredClone` at Sharing objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). | |
| - The implementation of {{domxref("structuredClone")}} has changed to instantiate objects in the `this` realm instead of the caller's realm. For backwards compatibility, the global scope of content scripts now has its own `structuredClone` method to continue allowing extensions to clone values in the content script's realm by default. This method shadows the `window.structuredClone` method, which remains available to allow extensions to clone values into the realm of the web page. For more information, see [`structuredClone` at Sharing objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). |
There was a problem hiding this comment.
| - The implementation of {{domxref("structuredClone")}} has changed to instantiate objects in the `this` realm instead of the caller's realm. For backwards compatibility, the global scope of content scripts now have its own `structuredClone` method to continue allowing extensions to clone values in the content script's realm by default. This method shadows the `window.structuredClone` method, which remains available to allow extensions to clone values into the realm of the web page. For more information, see [`structuredClone` at Sharing objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). | |
| - The implementation of {{domxref("structuredClone")}} has changed to instantiate objects in the `this` realm instead of the caller's realm. For backwards compatibility, the global scope of content scripts now includes a `structuredClone` method, allowing extensions to continue cloning values in the content script's realm by default. This method shadows the `window.structuredClone` method, which remains available to allow extensions to clone values into the web page's realm. For more information, see [`structuredClone` in Sharing objects with page scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). |
There was a problem hiding this comment.
None of us saw, forgot to save my own edit to fix that.
files/en-us/mozilla/add-ons/webextensions/sharing_objects_with_page_scripts/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Rob Wu <rob@robwu.nl>
| > The cross-browser {{domxref("structuredClone")}} method can also be used to create structured clones. | ||
| > |
There was a problem hiding this comment.
I originally provided this suggestion so that there is a mention and link to structuredClone on this page. In the latest version there is already a mention somewhere else, so I'm now proposing to drop it to keep this NOTE simple.
| > The cross-browser {{domxref("structuredClone")}} method can also be used to create structured clones. | |
| > |
|
|
||
| - 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. | ||
| A content script may encounter JavaScript objects from its global scope or Xray-wrapped versions from the web page. In regular web pages, {{domxref("globalThis")}} is identical to `window`, but in Firefox's content scripts, `globalThis` is a distinct object inheriting from `window`. This distinction often makes no practical difference for the availability of global APIs. The exception is when the global scope contains a definition of a standard API that shadows the definition in `window`, such as [`structuredClone` in content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). |
There was a problem hiding this comment.
globalThis is rendered as a red non-existing link. Perhaps it should be jsxref instead of domxref? I'm not sure, please try it and otherwise find the right version of the syntax. It is supposed to point to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis
| A content script may encounter JavaScript objects from its global scope or Xray-wrapped versions from the web page. In regular web pages, {{domxref("globalThis")}} is identical to `window`, but in Firefox's content scripts, `globalThis` is a distinct object inheriting from `window`. This distinction often makes no practical difference for the availability of global APIs. The exception is when the global scope contains a definition of a standard API that shadows the definition in `window`, such as [`structuredClone` in content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). | |
| A content script may encounter JavaScript objects from its global scope or Xray-wrapped versions from the web page. In regular web pages, {{jsxref("globalThis")}} is identical to `window`, but in Firefox's content scripts, `globalThis` is a distinct object inheriting from `window`. This distinction often makes no practical difference for the availability of global APIs. The exception is when the global scope contains a definition of a standard API that shadows the definition in `window`, such as [`structuredClone` in content scripts](/en-US/docs/Mozilla/Add-ons/WebExtensions/Sharing_objects_with_page_scripts#structuredclone). |
|
|
||
| The purpose of this feature is to make it harder for the less-privileged script to confuse the more-privileged script by redefining the native properties of objects. | ||
|
|
||
| So, for example, when a content script accesses the page's [window](/en-US/docs/Web/API/Window), it won't see any properties the page script added to the window, and if the page script has redefined any existing properties of the window, the content script will see the original version. |
There was a problem hiding this comment.
Cross link the content script environment section because we now have additional information there about globalThis that is relevant. Not sure if this is the best way to document it, or if we should just add an extra sentence in the end.
| So, for example, when a content script accesses the page's [window](/en-US/docs/Web/API/Window) from a [content script environment](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_scripts#content_script_environment), it won't see any properties the page script added to the window, and if the page script has redefined any existing properties of the window, the content script will see the original version. |
Description
Addresses the dev-docs-needed request Bug 2017797 Clipboard2File stopped working in Firefox Nightly.