Back to Content

WorkerGlobalScope: structuredClone() method

files/en-us/web/api/workerglobalscope/structuredclone/index.md

latest1.9 KB
Original Source

{{APIRef("Web Workers API")}}{{AvailableInWorkers("worker")}}

The structuredClone() method of the {{domxref("WorkerGlobalScope")}} interface creates a {{Glossary("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-nolint
structuredClone(value)
structuredClone(value, options)

Parameters

  • value
  • options {{optional_inline}}
    • : An object with the following properties:
      • transfer

Return value

A {{Glossary("deep copy")}} of the original value.

Exceptions

  • DataCloneError {{domxref("DOMException")}}
    • : Thrown if any part of the input value is not serializable.

Description

See {{domxref("Window.structuredClone()")}} for details of this function.

Examples

See {{domxref("Window.structuredClone()")}} for examples.

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also