Page MenuHomePhabricator

Uncaught TypeError: navigator.sendBeacon is not a function
Closed, ResolvedPublic

Description

Uncaught TypeError: navigator.sendBeacon is not a function
    jQuery 3
        submit
        flush
        BackgroundQueue

I get this all the time, especially when navigating away from a tab or when searching for something. To replicate:

  1. Search for something. Doesn't seem to matter whether you "go" to the result (i.e. entering Macbeth into the search bar) or you look at the advanced result (clicking "search" on Special:Search). Error shows up.
  2. Navigate away from that tab, then return. Error shows up.

Time being what it is these days, I don't remember when I first noticed it; maybe December (or November?) on testwiki?

Event Timeline

Aklapper added a subscriber: Kizule.

@Kizule: MediaWiki-Search is not used on Wikimedia wikis and I don't see yet how that's related to some search code base...

@Amorymeltzer If you can reliably reproduce, can you please use debug=true (see https://www.mediawiki.org/wiki/Help:Locating_broken_scripts ) and provide a location for the Uncaught TypeError: navigator.sendBeacon is not a function line?

Extensions which include that line are Popups, MultimediaViewer, QuickSurveys, CantralNotice, Cite, WikimediaEvents, EventLogging itself, so help in tracking this down would be welcome (I have not managed to reproduce so far).

@Aklapper it's navigator.sendBeacon(config.serviceUri, JSON.stringify(eventData)); in the core.submit definition, which, from codesearch, is from the Event Logging extension: https://gerrit.wikimedia.org/g/mediawiki/extensions/EventLogging/+/a27b4a1f3d235ace86d93c4f2bb4a60fcb7c9b97/modules/ext.eventLogging/core.js#398

@Kizule: MediaWiki-Search is not used on Wikimedia wikis and I don't see yet how that's related to some search code base...

I thought that it is related, as this is a task related to the search.

@Ottomata Firefox 78, but I also get it in Safari; a quick test suggested I wasn't seeing it in Chrome?

@Amorymeltzer: I believe you, but something's not making sense. navigator.sendBeacon has been available in Firefox since v31, in 2014 (https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) and your version is just from May of last year. Something is disabling / removing navigator.sendBeacon somehow. Could be some rogue code executing from an extension in your browser, gadget you have enabled, etc. I found very few references to other folks experiencing the same problem, like this obscure chat (look for the error): https://mozilla.logbot.info/fxos/20151112/raw.

Let's try these steps to figure it out more:

  1. go to www.google.com
  2. open up the dev tools, type navigator.sendBeacon in the console, is it there, or undefined?
  3. navigate to your wiki (what wiki are you looking at btw), check again, is it there, or undefined?
  4. do your test, go back to the console and check again, is it there?

My thinking is:

  • if you don't see it in 2. then some browser extension is removing it for some reason
  • if you do, but then don't see it in 3. then something you install from our universe (gadget, user script, etc.) is messing with it
  • if you do again, but don't see it in 4. then it could be some other code we wrote somewhere messes with it, in this case please share your username so we can figure out what preferences you have enabled and troubleshoot that way
  • if you see it fine in all cases, then it means just the code path that gets to sending the event messes with sendBeacon and I guess this might be similar to the above

I'm just trying to be very systematic, as I couldn't reproduce it myself and this code runs billions of times apparently without producing this problem.

@Milimetric Ach yeah, it'll be some ad blocker. Haven't figured out which yet, but sorry for hassle. I've also just found T86680, which makes it clear.

My issue (and, presumably, others) here likely arises from https://gerrit.wikimedia.org/r/c/mediawiki/extensions/EventLogging/+/573677, which used navigator.sendBeacon rather than core.sendBeacon, where the error handling is dealt with. Would replacing the former with the latter work as intended?

Huh, yeah we should wrap the new navigator.sendBeacon call with a similar check, and perhaps just log a more informative console error.

FYI @Mholloway ^

Change 661378 had a related patch set uploaded (by Ottomata; owner: Ottomata):
[mediawiki/extensions/EventLogging@master] Use core.sendBeacon in core.submit to avoid JS errors

https://gerrit.wikimedia.org/r/661378

fdans moved this task from Incoming to Event Platform on the Analytics board.

Change 661378 had a related patch set uploaded (by Ottomata; owner: Ottomata):
[mediawiki/extensions/EventLogging@master] Use core.sendBeacon in core.submit to avoid JS errors

https://gerrit.wikimedia.org/r/661378

Change 661378 merged by jenkins-bot:
[mediawiki/extensions/EventLogging@master] Use core.sendBeacon in core.submit to avoid JS errors

https://gerrit.wikimedia.org/r/661378

Change 739355 had a related patch set uploaded (by Krinkle; author: Krinkle):

[mediawiki/extensions/EventLogging@master] Move support for POST data from sendBeacon() back to submit()

https://gerrit.wikimedia.org/r/739355

Change 739355 merged by jenkins-bot:

[mediawiki/extensions/EventLogging@master] Move support for POST data from sendBeacon() back to submit()

https://gerrit.wikimedia.org/r/739355