Fixed now. This was a fun one. Long story short: It wasn't Microsoft's fault, it was ours. If you're curious about the dirty details, here goes:
The ad is loaded in a IFRAME. The ad provider needs to communicate between the main page and the IFRAME, which means cross-origin communication. Since IE8 we've had the postMessage
API to do that sort of thing, but that's a little too modern apparently.
So instead, in order to perform this communication, it's using a well-known hack (example) that uses window.name
to talk between the IFRAME and the parent. It looks like this is used to send some blob of HTML over to the IFRAME; either way, the IFRAME's window.name
contains a long string of stuff.
Once the IFRAME is done with whatever it needs to do, it's being a nice citizen and cleans up after itself, by setting its window.name
back to the empty string. So far so good.
And now for something completely different. The image upload popup is loaded via a little JavaScript helper in our code called asyncLoad
. This helper has an option called callback
, documented like this:
callback: An additional explicit callback, used only as fallback if the '.async-load'
element has no 'data-after-load' attribute. Can be null/undefined.
In the case of the image uploader, this parameter is not null or undefined; rather, it's the callback that actually initializes the dialog (adds functionality, hides stuff that shouldn't be visible, etc.)
Now, as that piece of documentation says, the asyncLoad
helper first checks for the data-after-load
attribute, and it parses it as a period-separated lookup. Here's the relevant code:
var func = $this.data('after-load') || '';
if (!func && !options.callback) {
return;
}
// after-load callbacks will usually be like "StackExchange.container.publicMethod"
// so need to get a reference at each level, e.g.
// window["StackExchange"]["container"]["publicMethod"]
var levels = func.split('.'),
toCall;
// callback should be accessable from window
for (var i = 0; i < levels.length; i++) {
toCall = (toCall || window)[levels[i]];
}
toCall = toCall || options.callback;
if (typeof toCall === 'function') {
toCall($this);
}
So it splits "StackExchange.container.publicMethod"
into ["StackExchange", "container", "publicMethod"]
. Then it looks up window["StackExchange"]
, on the result of that it looks up ["container"]
, etc.
Now what happens in the case of our image upload popup, where the callback
parameter is provided but the data-after-load
attribute isn't?
In that case, func
is an empty string, thus func.split(".")
is a single-element array [""]
. So the for
loop executes a single time:
toCall = (toCall || window)[levels[i]];
translates to
toCall = (toCall || window)[""];
translates to
toCall = window[""];
Hmm. That doesn't exactly look intentional, but fortunately it works anyways. Because there isn't actually a property with the empty name on the global object, toCall
is undefined
, and thus after
toCall = toCall || options.callback;
toCall
is actually our option-provided callback.
So while this sort of only works by accident, it works.
Well, it worked. Until this ad came along. Rember how I said that it cleaned up after itself by erasing the IFRAME's window.name
?
Let me quote from the spec that defines named access on the window
object, emphasis mine:
Let childBrowsingContexts be all document-tree child browsing contexts of activeDocument's browsing context whose browsing context name is not the empty string, in order, and including only the first document-tree child browsing context with a given name if multiple document-tree child browsing contexts have the same one.
It turns out that Chrome ignores the part I've bolded. And thus because the IFRAME set its window.name
to the empty string, the main page's window[""]
is now the IFRAME (or rather, its WindowProxy
).
Which is why toCall = window[""];
no longer is undefined
, and doesn't get replaced by the callback
parameter, thus the callback
is never called, and therefore the image uploader popup is not initialized.
And because there's a typeof
check, we never attempt to execute toCall
(which is why you didn't see an exception in the console).
So... that's it.
Here's the whole fix for this issue:
As I said, this was fun.