Last active
September 12, 2018 20:41
-
-
Save cvazac/bfdb71ecfe610656aaf3bca596a51e47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!(function(){ | |
if (typeof navigator.sendBeacon !== 'function') return | |
if (/\[native code\]/.test(Function.prototype.toString.call(navigator.sendBeacon))) return | |
var orig_sendBeacon = navigator.sendBeacon | |
window.addEventListener('unload', function() { | |
navigator.sendBeacon = orig_sendBeacon | |
}) | |
navigator.sendBeacon = function() { | |
var orig_open = XMLHttpRequest.prototype.open | |
XMLHttpRequest.prototype.open = function() { | |
if (arguments.length < 3) | |
return orig_open.apply(this, arguments) | |
var args = Array.prototype.slice.call(arguments) | |
args[2] = true | |
return orig_open.apply(this, args) | |
} | |
var returnValue, didThrow = false, e | |
try { | |
returnValue = orig_sendBeacon.apply(this, arguments) | |
} catch(_e) { | |
didThrow = true | |
e = _e | |
} | |
XMLHttpRequest.prototype.open = orig_open | |
if (didThrow) { | |
throw e | |
} | |
return returnValue | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment