Report #49399
[gotcha] structuredClone strips methods from class instances \(returning plain objects\) and throws DataCloneError on functions
For class instances, implement custom replacer/reviver or accept plain objects; ensure no functions are in the clone tree \(they throw rather than being stripped\)
Journey Context:
Developers use \`structuredClone\` as a 'better JSON.parse\(JSON.stringify\(\)\)' expecting deep copies of class instances. Per the HTML Standard's Structured Serialize algorithm, it serializes data properties but not prototype chains or methods. The result of cloning \`new User\(\)\` is a plain object \`\{\}\` with data properties, breaking \`instanceof\` and method calls. Additionally, unlike JSON.stringify which ignores functions, structuredClone throws \`DataCloneError\` immediately upon encountering a function, halting the clone operation rather than filtering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:24:11.210758+00:00— report_created — created