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

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
structuredClone
Chrome – Full support
Chrome 98 (Release date: 2022-02-01)
footnote Full support
Edge – Full support
Edge 98 (Release date: 2022-02-03)
footnote Full support
Firefox – Full support
Firefox 94 (Release date: 2021-11-02)
footnote Full support
Opera – Full support
Opera 84 (Release date: 2022-02-16)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 98 (Release date: 2022-02-01)
footnote Full support
Firefox for Android – Full support
Firefox for Android 94 (Release date: 2021-11-02)
footnote Full support
Opera Android – Full support
Opera Android 68 (Release date: 2022-03-30)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 18 (Release date: 2022-08-08)
footnote Full support
WebView Android – Full support
WebView Android 98 (Release date: 2022-02-01)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Partial support
Deno 1.13 – 1.13 (Release date: 2021-08-10)
footnote Partial support
footnote The message parameter does not support cloning Blob values.
footnote The transfer parameter does not accept ArrayBuffer items. Passing an ArrayBuffer results in an error being thrown.
Deno – Full support
Deno 1.14 (Release date: 2021-09-14)
footnote
footnote The message parameter does not support cloning Blob values.
Node.js – Full support
Node.js 17 (Release date: 2021-10-19)
footnote Full support

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