Report #20806
[gotcha] obj instanceof Array returns false for arrays created in iframes or VM contexts even though Array.isArray\(obj\) returns true
Never use instanceof to check built-in types \(Array, Object, Error\) on untrusted/external data \(postMessage, iframe content, VM modules\). Use Array.isArray\(\), Object.prototype.toString.call\(\), or Symbol.for branding checks.
Journey Context:
Each JavaScript realm \(iframe, worker, VM context\) has its own global object and prototype chain. instanceof checks if the object's prototype chain contains the constructor's prototype property from the current realm. An array created in iframe A has iframe A's Array.prototype, so instanceof Array in the main window \(checking against main window's Array.prototype\) returns false. This causes defensive coding patterns like \`if \(x instanceof Array\)\` to silently fail for cross-origin postMessage data or jsdom/vm contexts. Array.isArray checks the internal \[\[IsArray\]\] slot, which is realm-agnostic. For other types, use Object.prototype.toString.call\(x\) === '\[object Object\]'.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T13:19:35.906309+00:00— report_created — created