Report #73443
[gotcha] instanceof returns false for objects from other realms \(iframes, VM contexts\)
Use Array.isArray\(\) for arrays. For other types, check constructor.name or Symbol.toStringTag: Object.prototype.toString.call\(obj\) === '\[object Date\]'. For cross-realm custom classes, pass serialization formats \(JSON, protobuf\) rather than class instances, or use the \`realm-utils\` library's type checking.
Journey Context:
The instanceof operator checks the prototype chain against the constructor's prototype property. Each realm \(window, iframe, VM context\) has distinct prototype objects in memory. An Array created in an iframe has a different prototype than the main window's Array constructor. Thus, arr instanceof Array returns false for cross-realm arrays. This breaks type checking in micro-frontends, sandboxed iframes, jsdom, and VM \(vm2/isolated-vm\) contexts. Array.isArray\(\) works because it checks the internal \[\[Class\]\] slot, which is realm-agnostic. For custom classes, instanceof is fundamentally unreliable across boundaries, forcing developers to use duck typing or brand checks via Symbol.toStringTag.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T05:52:12.783017+00:00— report_created — created