navigator.sendbeacon
Advanced tools
Comparing version 0.0.14 to 0.0.15
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e():"function"==typeof define&&define.amd?define(e):e()}(0,function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(e)}var e=function(t){return"string"==typeof t},n=function(t){return t instanceof Blob};(function(){if(function(){return"navigator"in this&&"sendBeacon"in this.navigator}.call(this))return;"navigator"in this||(this.navigator={});this.navigator.sendBeacon=function(t,o){var i=this.event&&this.event.type,r="unload"===i||"beforeunload"===i,u="XMLHttpRequest"in this?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");u.open("POST",t,!r),u.withCredentials=!0,u.setRequestHeader("Accept","*/*"),e(o)?(u.setRequestHeader("Content-Type","text/plain;charset=UTF-8"),u.responseType="text/plain"):n(o)&&o.type&&u.setRequestHeader("Content-Type",o.type);try{u.send(o)}catch(t){return!1}return!0}.bind(this)}).call("object"===("undefined"==typeof window?"undefined":t(window))?window:{})}); | ||
//# sourceMappingURL=navigator.sendbeacon.min.js.map |
{ | ||
"name": "navigator.sendbeacon", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Polyfill for navigator.sendBeacon()", | ||
@@ -16,3 +16,4 @@ "main": "dist/navigator.sendbeacon.cjs.js", | ||
"prepublish": "npm run build", | ||
"release": "np" | ||
"release": "np", | ||
"lint": "standard --fix *.js" | ||
}, | ||
@@ -37,4 +38,12 @@ "repository": { | ||
"np": "^3.0.4", | ||
"rimraf": "^2.6.2" | ||
"rimraf": "^2.6.2", | ||
"standard": "^14.3.1" | ||
}, | ||
"standard": { | ||
"globals": [ | ||
"Blob", | ||
"XMLHttpRequest", | ||
"ActiveXObject" | ||
] | ||
} | ||
} |
@@ -1,41 +0,40 @@ | ||
const isString = val => typeof val === 'string'; | ||
const isBlob = val => val instanceof Blob; | ||
const isString = val => typeof val === 'string' | ||
const isBlob = val => val instanceof Blob | ||
polyfill.call(typeof window === 'object' ? window : this || {}); | ||
polyfill.call(typeof window === 'object' ? window : this || {}) | ||
function polyfill() { | ||
if (isSupported.call(this)) return; | ||
function polyfill () { | ||
if (isSupported.call(this)) return | ||
if (!('navigator' in this)) this.navigator = {}; | ||
this.navigator.sendBeacon = sendBeacon.bind(this); | ||
}; | ||
if (!('navigator' in this)) this.navigator = {} | ||
this.navigator.sendBeacon = sendBeacon.bind(this) | ||
} | ||
function sendBeacon(url, data) { | ||
const event = this.event && this.event.type; | ||
const sync = event === 'unload' || event === 'beforeunload'; | ||
function sendBeacon (url, data) { | ||
const event = this.event && this.event.type | ||
const sync = event === 'unload' || event === 'beforeunload' | ||
const xhr = ('XMLHttpRequest' in this) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP'); | ||
xhr.open('POST', url, !sync); | ||
xhr.withCredentials = true; | ||
xhr.setRequestHeader('Accept', '*/*'); | ||
const xhr = ('XMLHttpRequest' in this) ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP') | ||
xhr.open('POST', url, !sync) | ||
xhr.withCredentials = true | ||
xhr.setRequestHeader('Accept', '*/*') | ||
if (isString(data)) { | ||
xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8'); | ||
xhr.responseType = 'text/plain'; | ||
xhr.setRequestHeader('Content-Type', 'text/plain;charset=UTF-8') | ||
xhr.responseType = 'text/plain' | ||
} else if (isBlob(data) && data.type) { | ||
xhr.setRequestHeader('Content-Type', data.type); | ||
xhr.setRequestHeader('Content-Type', data.type) | ||
} | ||
try { | ||
xhr.send(data); | ||
xhr.send(data) | ||
} catch (error) { | ||
return false; | ||
return false | ||
} | ||
return true; | ||
return true | ||
} | ||
function isSupported() { | ||
return ('navigator' in this) && ('sendBeacon' in this.navigator); | ||
function isSupported () { | ||
return ('navigator' in this) && ('sendBeacon' in this.navigator) | ||
} |
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
10292
4
9
184