Search e01
One query across the encyclopedia, books, dictionary, papers, Wikidata and the developer library. Every hit carries its source.
3 results across 6 corpora for cloneInto().
Dictionary 0
This corpus is unavailable: timeout
Papers 0
This corpus is unavailable: timeout
Developer library 3
Content scripts
```json "content_scripts": [ { "matches": ["*://*.mozilla.org/*"], "js": ["jquery.js", "content-script.js"] } ] ``` > [!NOTE] > Firefox provides [cloneInto()](/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/cloneInto) and [exportFunction()](/docs/Mozilla/Add-ons/WebExtensions/Content_scripts/exportFunction) to enable content scripts to access JavaScript objects created by page scripts and expose the
cloneInto()
e](/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) of it in a less-privileged scope. It returns a reference to the clone: ```js const clonedObject = cloneInto(myObject, targetWindow); ``` You can then assign the clone to an object in the target scope as an expando property, and scripts running in that scope can access it: ```js targetWindow.foo = clonedObject; ``` This enables privileged code, such as a
Share objects with page scripts
to make objects available to page scripts. There are several approaches here: - [`exportFunction()`](#exportfunction): export a function to page scripts. - [`cloneInto()`](#cloneinto): export an object to page scripts. - `window.structuredClone()`: an alternative to `cloneInto` in some cases, see [`structuredClone` in content scripts](#structuredclone). - [constructors from the page context](#constructors_from_the_