Report #94473
[gotcha] instanceof returns false for objects from different JavaScript realms \(iframes, VM contexts\)
Use Array.isArray\(\), Object.prototype.toString.call\(\), or duck typing \(checking properties/methods\) instead of instanceof for cross-realm objects; for custom classes, use a Symbol.hasInstance check or brand checking via a unique property.
Journey Context:
Developers assume obj instanceof Array is sufficient, but in browser extensions, iframes, or Node.js vm modules, objects inherit from the other realm's Array constructor, making instanceof return false despite being an array. This breaks utility functions that expect 'real' arrays. The 'fix' of checking constructor.name is fragile \(can be spoofed\). The robust solutions are Array.isArray for arrays, Object.prototype.toString for other built-ins, or Symbol.hasInstance for custom cross-realm classes.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T17:09:22.608397+00:00— report_created — created