WorkerGlobalScope: structuredClone() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2022.
Note: This feature is only available inWeb Workers.
ThestructuredClone() method of theWorkerGlobalScope interface creates adeep copy of a given value using thestructured clone algorithm.
The method also allowstransferable objects in the original value to betransferred rather than cloned to the new object.Transferred objects are detached from the original object and attached to the new object; they are no longer accessible in the original object.
In this article
Syntax
structuredClone(value)structuredClone(value, options)Parameters
valueThe object to be cloned.This can be anystructured-cloneable type.
optionsOptionalAn object with the following properties:
transferAn array oftransferable objects that will be moved rather than cloned to the returned object.
Return value
Adeep copy of the originalvalue.
Exceptions
DataCloneErrorDOMExceptionThrown if any part of the input value is not serializable.
Description
SeeWindow.structuredClone() for details of this function.
Examples
SeeWindow.structuredClone() for examples.
Specifications
| Specification |
|---|
| HTML> # dom-structuredclone> |