Report #15761
[gotcha] structuredClone throws DataCloneError for functions, DOM nodes, and prototype chains
Strip functions and DOM references before cloning, or implement custom serialization for complex objects. Use \`JSON.parse\(JSON.stringify\(obj\)\)\` only if the data is JSON-safe and prototype loss is acceptable.
Journey Context:
The HTML Standard specifies that \`structuredClone\` uses the Structured Serialize algorithm, which explicitly rejects functions, DOM nodes \(like \`Element\`\), and objects with non-serializable prototype chains \(e.g., class instances with methods\). Unlike JSON methods, which silently drop functions and stringify objects, \`structuredClone\` throws a \`DataCloneError\`. Developers often assume it is a 'deep clone' utility similar to \`\_.cloneDeep\`, attempting to clone class instances with methods or cached DOM references, resulting in runtime exceptions in Web Workers or postMessage calls.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:54:31.084978+00:00— report_created — created