24

This has happened a few times for me over the past week or so but this now it seems to be happening consistently:

Ms Advert:

enter image description here

No MS advert:

enter image description here

Doesn't seem to affect meta.

  • No console errors
  • can't see anything getting blocked, etc in the network tab
  • Disabled all extensions
  • Recreated in incognito mode.

Browser is Chrome 61.0.3163.100.

I've tried clearing the cache, etc.

Though the question is similar to this issue I don't believe this is my virus software that's causing this issue. I have only seen this issue when being server the Microsoft ad (see answer). With different ad (different SE sites, etc.) the image upload works.

20
  • That file size error shows up when you open the modal?
    – Cerbrus
    Commented Oct 16, 2017 at 8:09
  • Yes, that's how it looks when I open it. Error and all
    – Liam
    Commented Oct 16, 2017 at 8:09
  • As Tanner mentioned: Any extensions?
    – Cerbrus
    Commented Oct 16, 2017 at 8:10
  • I've just disabled all extension, same issue. Also checked in incognito mode, and same issue.
    – Liam
    Commented Oct 16, 2017 at 8:10
  • Nope I'm getting it on questions. The one I'm testing is this, no answers on it.
    – Liam
    Commented Oct 16, 2017 at 8:13
  • 1
    Maybe same as these? meta.stackoverflow.com/questions/357591 | meta.stackoverflow.com/questions/357411
    – Pang
    Commented Oct 16, 2017 at 8:16
  • 4
    Possible duplicate of Can't upload image anymore
    – Cerbrus
    Commented Oct 16, 2017 at 8:21
  • 1
    I think it's related to ads in the sidebar, see my answer.
    – Tanner
    Commented Oct 16, 2017 at 8:28
  • @liam was able to fix that post as proof once the ad was not present.
    – Tanner
    Commented Oct 16, 2017 at 8:31
  • I do appreciate the dupe @Cerbrus, the answer though, I'm not using McAffee, I have bit defender, work computer so I can't disable it. I think Taner might have it. It works on other SE sites (which doesn't have this advert). I can't find a question where that isn't served to prove yet
    – Liam
    Commented Oct 16, 2017 at 8:33
  • 3
    Blame Microsoft, see my latest update to answer.
    – Tanner
    Commented Oct 16, 2017 at 8:35
  • 1
    @Cerbrus i think this one should stay open though and the other closed, as this has more details now and a possible cause.
    – Tanner
    Commented Oct 16, 2017 at 8:43
  • 1
    Repro'd on Android Chrome. Definitely not McAfee, Norton, or any other antivirus.
    – Mike M.
    Commented Oct 16, 2017 at 9:05
  • 3
    FWIW, just got it with a non-Microsoft ad: i.sstatic.net/M0vlh.jpg. (It's Android Chrome on the desktop site, which is why the scrim is off.)
    – Mike M.
    Commented Oct 16, 2017 at 9:35
  • 3
    @Tanner Just posted. As you can see, it took a while to write it up :)
    – balpha StaffMod
    Commented Oct 16, 2017 at 13:27

2 Answers 2

30

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:

screenshot of a diff that causes levels to be the empty array if func is empty

As I said, this was fun.

6
  • 1
    Deep... So was it just that Ad or were other ads from the same provider causing the issue too? That was the only one I was able to repro the issue on consistently, the MS bit was just a joke. Or is it simply because I was seeing that ad most based on the tags I frequent.
    – Tanner
    Commented Oct 16, 2017 at 13:32
  • 1
    I don't know, it may have been more than this one. We also recently transitioned to a new ad provider. So this might eventually have become more frequent.
    – balpha StaffMod
    Commented Oct 16, 2017 at 13:36
  • 2
    @Tanner - I've seen others ads reported as causing the same problem.
    – Oded StaffMod
    Commented Oct 16, 2017 at 13:41
  • 1
    Good work guys, I always think the more inconsequential the fix the more difficult it is to figure out the problem.
    – Liam
    Commented Oct 16, 2017 at 13:53
  • As an aside @balpha did you know the link in your profile throws an error? unicornify.appspot.com Python 2.5 is no longer available
    – Liam
    Commented Oct 16, 2017 at 13:55
  • 1
    Apologies to Microsoft. This time.
    – Gimby
    Commented Oct 17, 2017 at 8:36
8

I've found what could be a consistent cause. I was testing with answering a question and inserting an image:

Fails with a Microsoft ad in the sidebar bar:

enter image description here

Refresh a page enough times until you don't see an ad in the sidebar and it seems to work. Reproduced in this scenario a few times now.

enter image description here

If you load a non-Microsoft tagged post to get a different ad, it also seems to work fine:

enter image description here

So Blame Microsoft

NOTE: I have Ghostery running, but it was disabled for these tests.

11
  • I also have that advert. Not sure if that proves the theory or not.
    – Liam
    Commented Oct 16, 2017 at 8:31
  • 1
    Managed to get a page with a different advert, works. I think you've got it
    – Liam
    Commented Oct 16, 2017 at 8:35
  • 2
    Good sleuthing dude.
    – Liam
    Commented Oct 16, 2017 at 8:42
  • Tanner ad this as an answer to the other and I'll close as a duplicate
    – Liam
    Commented Oct 16, 2017 at 8:43
  • 1
    @Liam we can just close that as a dupe of this, as there is more details here. I've already voted on the other post and pinged Oded.
    – Tanner
    Commented Oct 16, 2017 at 8:44
  • What question are you getting that ad on? I can't even get is to display on an asp.net question.
    – Cerbrus
    Commented Oct 16, 2017 at 8:46
  • 3
    @Cerbrus Try here stackoverflow.com/questions/46765483/…. I get it consistently. It's hard for me to find a question without an MS advert but I work in C# so maybe being targeted.
    – Liam
    Commented Oct 16, 2017 at 8:47
  • @Cerbrus try: stackoverflow.com/questions/46765145/…
    – Tanner
    Commented Oct 16, 2017 at 8:47
  • Same pattern of ads, no MS ad, so kinda hard to check if it's reproducible (for me) :-/
    – Cerbrus
    Commented Oct 16, 2017 at 8:48
  • Yeah, see I don't get an MS advert there. I'm guessing it depends on the advert targeting algorithm. even in incognito I struggle to find a question that doesn't serve that advert
    – Liam
    Commented Oct 16, 2017 at 8:49
  • See mainly MS ads under posts on sql-server, although i'm struggling at the moment to get one. The algorithm must think i've been shown enough MS ads today with the amount of refreshing I've done :-)
    – Tanner
    Commented Oct 16, 2017 at 8:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .