Keep in mind that a large portion of users have sendbeacon disabled for privacy reasons. Disabling in Firefox via the
navigator.sendBeacon so the fallback should work.
The popular open source adblocker
uBlock origin also has a (enabled by default) setting to remove sendbeacon and
<a ping>, but in my test the request still worked.
So we should do a lot of testing to avoid the fallback not working (e.g. if
navigator.sendBeacon still exists, but is blocked).
One thing to keep in mind is that the callback parameter won't work anymore (because there is no event or what so ever when the request is finished). Some users rely on this see eg https://github.com/matomo-org/matomo/issues/13679#issuecomment-436748761
Actually, callbacks won't be a problem cause we call the callback if the browser confirms it sent the request.
They are sent as request parameters unless the request is large AFAIK
Also we just found out that when closing the tab/window, Chrome seems to not execute sendBeacon on beforeunload unfortunately!? so we wouldn't want to rely on this feature probably...
@mattab it's still good for sending requests when the browser closes. It will be more reliable than the XHR. It just means we can't collect all requests, optimize them, and send them at the end of the page view. Like instead of pinging Matomo every 15s using heartbeat it would have better to send only one request when the browser closes... but this won't work reliably