Report #92823
[gotcha] structuredClone throws DataCloneError for functions, DOM nodes, or certain built-in objects
Pre-filter objects to strip functions and DOM references before cloning; for complex graphs with cycles, use flatted library or manual serialization instead of structuredClone
Journey Context:
structuredClone uses the HTML Structured Serialize algorithm which explicitly forbids functions \(not serializable\), DOM nodes \(main-thread bound\), and certain internal slots like those in Regex lastIndex or Promise state. Many assume it is a drop-in replacement for JSON.parse\(JSON.stringify\(\)\) with better type support, but it is stricter in critical ways. The error manifests as a DataCloneError only at runtime when the clone encounters the forbidden type deep in the object graph.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T14:23:30.139678+00:00— report_created — created