Incredibly Strange iOS Issue

Update 8/19/2010 @ 11:55 EDT

It looks like this may be a cross-domain issue after all.  I changed my testing methodology and was able to reproduce this issue without Gmail being involved. That's the good news, the bad news is that even in a cross-domain scenario, access should simply be denied to the properties or an exception should be thrown.  In this case in Mobile Safari, the script dies at the point in execution where it attempts to access the property.


I'm posting this to my blog in hopes of finding some help; I'd love to file this issue as a bug report but I have no idea if it's a bug in Gmail or a bug in Mobile Safari.  I'm inclined to think the latter; but the fact that I can consistently reproduce this issue in the manner described below leads me to think it could be something crazy that Gmail does.


The window.opener object is available on browser windows that have been spawned by other browser windows (either using Javascript or the classic target="_blank"). It's a reference to a window object. In general, it behaves entirely as expected on the iOS; except when you click a link from Gmail (and the issue occurs whether you're using the Mobile Gmail version or the desktop version on an iOS device).

What Happens?

Clicking a link from Gmail on an iOS device causes the link to open in a new browser window. However, if you have a page that attempts to reference any properties of the window.opener object, you'll receive the error:

TypeError: no default value

Here's where it gets really strange, if I evaluate the window.opener object itself in any way, it reports that its a DOMWindow object. However, if I try to enumerate the properties of that object none are found.  If I try to access a property of a DOMWindow object by name, I receive the above error.

What I've Tried

I've tried and ruled out several possible methods of reproducing this issue without Gmail; in each case the window.opener object behaved normally and I was able to both enumerate the properties and read a property directly without an error:

  • I created a page with a link using target="_blank"
  • I created a page using Javascript's to open a link
  • I hosted the pages on different domains to see if there was some cross-domain issue affecting it.

I've also tried a few workarounds; none of which prevented the error:

  • Check for the presence window.opener.location (or any specific property) before using it in an assignment.
  • Wrapping any references to properties of window.opener in a try / catch.

At this point, I'm pretty well stumped on what's happening here; or if there's any way for me to work around it.  I've set up a demo that I encourage you to email to yourself so you can see this bug in action.   Turn on the debug console in MobileSafari, click that link from the gmail web app, and you'll see the errors.  Click that link from anywhere else, you'll get every property of the window.opener object written to your console.

You can test this on the devices themselves or the emulators; the behavior is consistent.

One more thing...

It just wouldn't be an Apple-related post without that line; Once you see the error, tap the icon to switch browser windows.  Safari will crash.