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 in Web Workers.

The structuredClone() method of the WorkerGlobalScope interface creates a deep copy of a given value using the structured clone algorithm.

The method also allows transferable objects in the original value to be transferred 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.

Syntax

js
structuredClone(value)
structuredClone(value, options)

Parameters

value

The object to be cloned. This can be any structured-cloneable type.

options Optional

An object with the following properties:

transfer

An array of transferable objects that will be moved rather than cloned to the returned object.

Return value

A deep copy of the original value.

Exceptions

DataCloneError DOMException

Thrown if any part of the input value is not serializable.

Description

See Window.structuredClone() for details of this function.

Examples

See Window.structuredClone() for examples.

Specifications

Specification
HTML
# dom-structuredclone

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
structuredClone

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
See implementation notes.
Has more compatibility info.

See also