Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy
JavaScript

JavaScript: Fix value instanceof Array Returning false for an Array Passed Across an iframe Boundary Because Each Window Has Its Own Array Constructor

- 08.11.26 - ErcanOPAK

⚑ JavaScript: Fix value instanceof Array Returning false for an Array Passed Across an iframe Boundary Because Each Window Has Its Own Array Constructor

Every JavaScript realm β€” the main page, and separately each iframe, popup window, or worker β€” has its own global object and therefore its own distinct set of built-in constructors, Array included. An array created inside an iframe and handed up to the parent page is a perfectly real array, but value instanceof Array fails in the parent’s realm, because that array’s prototype chain points to the iframe’s Array.prototype, not the parent window’s.

πŸ”Ž The Problem

// inside the iframe:
window.parent.receivedArray = [1, 2, 3];

// in the parent page:
console.log(window.receivedArray instanceof Array); // false
console.log(Array.isArray(window.receivedArray));   // true

βœ… Fix: Check Array-ness Without Checking Whose Array It Is

  • Use Array.isArray(value) instead of instanceof Array β€” it was specifically designed to correctly identify arrays regardless of which realm (iframe, window, worker) created them, by checking the object’s internal array exotic-object slot rather than walking one particular realm’s prototype chain.
  • If you genuinely need instanceof for a custom type (not Array itself) across a realm boundary, compare against the constructor the OTHER realm actually used β€” for example iframe.contentWindow.SomeClass β€” rather than the one from your own scope.
  • When architecting cross-frame communication, prefer passing data through structuredClone or JSON serialization at the boundary whenever exact class identity doesn’t need to be preserved, since that sidesteps realm-identity mismatches for Arrays, Dates, and other built-ins entirely.

🚨 Why This Is Dangerous

This failure mode is especially confusing because the value genuinely IS an array in every observable way β€” Array.isArray on it returns true, bracket indexing works, .length is correct β€” so a check built only around instanceof can send debugging effort toward β€œwhy is this not an array” when the real answer is β€œit’s an array from a different realm than the one you’re comparing against.”

instanceof asks ‘does this object’s prototype chain include YOUR Array,’ and across an iframe boundary the honest answer is no β€” it includes a different window’s Array that happens to work exactly the same way.

β€” JavaScript Tip

Related posts:

Get and Use TextBox Values with Javascript

Get and Use TextBox Values with Javascript

Abort Fetch Requests to Prevent UI Race Conditions

Abort Fetch Requests to Prevent UI Race Conditions

JavaScript: Use Proxy to Create Reactive Objects Without Framework

JavaScript: Use Proxy to Create Reactive Objects Without Framework

Views: 9

Post navigation

Photoshop: Fix Text Set in a Non-Latin Font Rendering as Empty Boxes in a Shared PSD Because That Font Is Only Installed on the Machine That Created the Document
Docker: Fix a Multi-Stage Build Reinstalling Every Dependency on Every Code Change Because COPY . . Runs Before the Package Install Step

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

November 2026
M T W T F S S
 1
2345678
9101112131415
16171819202122
23242526272829
30  
« Oct    

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (854)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (653)
  • Add Constraint to SQL Table to ensure email contains @ (608)
  • Average of all values in a column that are not zero in SQL (570)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (546)
  • Find numbers with more than two decimal places in SQL (475)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit
  • SQL Server: Fix ROW_NUMBER Ties Reordering Between Identical Runs
  • C#: Fix an Enum HasFlag Returning True for the Zero Value
  • WordPress: Fix Featured Images Vanishing After a CDN Migration
  • Photoshop: Fix Content-Aware Fill Smearing a Repeating Pattern
  • Asp.Net Core: Fix Antiforgery Tokens Rejected Behind a Reverse Proxy

Most Viewed Posts

  • How to make theater mode the default for Youtube (1,055)
  • Get the User Name and Domain Name from an Email Address in SQL (980)
  • How to add default value for Entity Framework migrations for DateTime and Bool (977)
  • Get the First and Last Word from a String or Sentence in SQL (857)
  • How to select distinct rows in a datatable in C# (854)

Recent Posts

  • C#: Fix a ConditionalWeakTable Entry Vanishing Too Soon
  • Docker: Fix a Stale COPY Layer After Editing .dockerignore
  • Photoshop: Fix a Pattern Overlay Scaling Wrong on a High-DPI File
  • SQL Server: Fix a Computed Column Index Skipped by Implicit Cast
  • HTML5: Fix a required Input Inside a Hidden Tab Blocking Submit

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com