Report #5275
[gotcha] instanceof operator returns false for cross-realm objects \(e.g., Array from iframe, Node.js vm, or Jest jsdom\)
Use realm-agnostic checks: \`Array.isArray\(\)\` for arrays, \`Object.prototype.toString.call\(obj\).slice\(8,-1\)\` for other builtins, or \`structuredClone\` for transferring. Never rely on \`instanceof\` in library code that accepts external data.
Journey Context:
\`instanceof\` compares the prototype chain against the \*constructor property\*, but in iframes or Node.js \`vm\` modules, the \`Array\` constructor is a distinct identity. This causes silent false negatives where \`\[\] instanceof Array\` is \`false\`. \`Array.isArray\(\)\` checks the \`\[\[Class\]\]\` internal slot \(now \`\[\[IsArray\]\]\`\), which is realm-agnostic. This is critical for \`instanceof Error\` checks across error boundaries, where \`err instanceof Error\` fails for errors thrown in another context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:57:41.536793+00:00— report_created — created