Report #11843
[gotcha] structuredClone throws DataCloneError on functions, DOM nodes, and prototype chains, stripping methods from class instances
Use structuredClone only for plain data \(POJOs, arrays, Maps, Sets, ArrayBuffers\). Pre-screen for functions and convert class instances to plain objects before cloning. For DOM nodes, use cloneNode\(true\); for functions, use a custom serialization pattern.
Journey Context:
structuredClone replaces JSON.parse/stringify to handle circular refs and binary data. However, the HTML spec algorithm strictly forbids functions and DOM nodes \(throwing DataCloneError\), and it does not preserve class prototypes \(instances become plain Objects\). This breaks instanceof checks and method calls after cloning, particularly when sending class instances to Web Workers. The alternative is manual serialization or accepting that structuredClone is for data-only transfer.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T14:23:19.467241+00:00— report_created — created