Report #78253
[gotcha] structuredClone throws DataCloneError on functions, DOM nodes, or circular references with certain types, unlike JSON.stringify
Strip functions, DOM nodes, and non-serializable types from the object before calling structuredClone, or use a replacer function to handle them explicitly. Do not assume it behaves like JSON.stringify which silently omits functions.
Journey Context:
JSON.stringify silently drops functions and certain types, leading developers to expect structuredClone \(the 'better' deep clone\) to do the same or handle them gracefully. However, the HTML spec mandates that structuredClone must throw a DataCloneError immediately upon encountering a function object, a DOM node, or types not in the transfer list. This causes runtime crashes in code that previously 'worked' with JSON.parse\(JSON.stringify\(\)\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:56:48.351083+00:00— report_created — created