I've been trying to send a beacon on beforeunload
and it seems to work on pretty much all modern browsers, except Chrome in incognito mode.
This is the code that works in all modern browsers, except Chrome in incognito mode:
window.onbeforeunload = function() {
navigator.sendBeacon("url");
}
Not even this code doesn't seem to work:
window.onbeforeunload = function() {
console.log('before unload')
}
Am I doing anything wrong or is it just Chrome's fault?
What's your setup (SO, Chrome version) ?
On Chrome 80.0.3987.116 / Ubuntu 64 and Chrome 79.0.3945.130 / Windows 10 the below snippet works falwlessy:
Screen of the request (incognito mode) sent on beforeunload:
Ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload