navigator.sendbeacon
Advanced tools
Comparing version 0.0.6 to 0.0.7
{ | ||
"name": "navigator.sendbeacon", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Polyfill for navigator.sendBeacon()", | ||
@@ -5,0 +5,0 @@ "main": "sendbeacon.js", |
@@ -9,2 +9,4 @@ # Navigator.sendBeacon polyfill | ||
Using NPM: | ||
```bash | ||
@@ -14,2 +16,8 @@ npm install navigator.sendbeacon | ||
Using JavaScript source: | ||
```html | ||
<script src="sendbeacon.js"></script> | ||
``` | ||
# Usage | ||
@@ -16,0 +24,0 @@ |
@@ -1,5 +0,8 @@ | ||
(function(root) { | ||
;(function(root) { | ||
'use strict'; | ||
function sendBeacon(url, data) { | ||
var isSupported = (('navigator' in root) && | ||
('sendBeacon' in root.navigator)); | ||
var sendBeacon = function (url, data) { | ||
var xhr = ('XMLHttpRequest' in window) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); | ||
@@ -12,3 +15,3 @@ xhr.open('POST', url, false); | ||
xhr.responseType = 'text/plain'; | ||
} else if (Object.prototype.toString.call(data) === '[object Blob]') { | ||
} else if (({}).toString.call(data) === '[object Blob]') { | ||
if (data.type) { | ||
@@ -19,6 +22,12 @@ xhr.setRequestHeader('Content-Type', data.type); | ||
xhr.send(data); | ||
try { | ||
xhr.send(data); | ||
} catch (error) {} | ||
return true; | ||
} | ||
if (isSupported) { | ||
sendBeacon = navigator.sendBeacon; | ||
} | ||
if (typeof exports !== 'undefined') { | ||
@@ -33,5 +42,5 @@ if (typeof module !== 'undefined' && module.exports) { | ||
}); | ||
} else if ('navigator' in root && !('sendBeacon' in root.navigator)) { | ||
} else if (!isSupported) { | ||
root.navigator.sendBeacon = sendBeacon; | ||
} | ||
})(this); | ||
})(window || this); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5771
9
38
28