abortcontroller-polyfill
Advanced tools
Comparing version 1.2.6 to 1.2.7
@@ -218,2 +218,7 @@ (function (global, factory) { | ||
function polyfillNeeded(self) { | ||
if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); | ||
return true; | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
@@ -220,0 +225,0 @@ // defining window.Request, and this polyfill need to work on top of unfetch |
@@ -216,2 +216,7 @@ 'use strict'; | ||
function polyfillNeeded(self) { | ||
if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); | ||
return true; | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
@@ -244,2 +249,3 @@ // defining window.Request, and this polyfill need to work on top of unfetch | ||
} | ||
var _patchTargets = patchTargets, | ||
@@ -249,6 +255,7 @@ fetch = _patchTargets.fetch, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController; | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === undefined ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController })) { | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL: __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL })) { | ||
return { fetch: fetch, Request: Request }; | ||
@@ -269,8 +276,24 @@ } | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal')) { | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
var signal = void 0; | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
Object.defineProperty(request, 'signal', { | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: signal | ||
}); | ||
} | ||
return request; | ||
@@ -308,2 +331,11 @@ }; | ||
if (init && init.signal) { | ||
// Never pass .signal to the native implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
@@ -310,0 +342,0 @@ return Promise.race([cancellation, realFetch(input, init)]); |
@@ -218,2 +218,7 @@ (function (global, factory) { | ||
function polyfillNeeded(self) { | ||
if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); | ||
return true; | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
@@ -246,2 +251,3 @@ // defining window.Request, and this polyfill need to work on top of unfetch | ||
} | ||
var _patchTargets = patchTargets, | ||
@@ -251,6 +257,7 @@ fetch = _patchTargets.fetch, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController; | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === undefined ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController })) { | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL: __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL })) { | ||
return { fetch: fetch, Request: Request }; | ||
@@ -271,8 +278,24 @@ } | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal')) { | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
var signal = void 0; | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
Object.defineProperty(request, 'signal', { | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: signal | ||
}); | ||
} | ||
return request; | ||
@@ -310,2 +333,11 @@ }; | ||
if (init && init.signal) { | ||
// Never pass .signal to the native implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
@@ -312,0 +344,0 @@ return Promise.race([cancellation, realFetch(input, init)]); |
@@ -218,2 +218,7 @@ (function (global, factory) { | ||
function polyfillNeeded(self) { | ||
if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); | ||
return true; | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
@@ -246,2 +251,3 @@ // defining window.Request, and this polyfill need to work on top of unfetch | ||
} | ||
var _patchTargets = patchTargets, | ||
@@ -251,6 +257,7 @@ fetch = _patchTargets.fetch, | ||
NativeRequest = _patchTargets$Request === undefined ? fetch.Request : _patchTargets$Request, | ||
NativeAbortController = _patchTargets.AbortController; | ||
NativeAbortController = _patchTargets.AbortController, | ||
_patchTargets$__FORCE = _patchTargets.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = _patchTargets$__FORCE === undefined ? false : _patchTargets$__FORCE; | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController })) { | ||
if (!polyfillNeeded({ fetch: fetch, Request: NativeRequest, AbortController: NativeAbortController, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL: __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL })) { | ||
return { fetch: fetch, Request: Request }; | ||
@@ -271,8 +278,24 @@ } | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal')) { | ||
if (Request && !Request.prototype.hasOwnProperty('signal') || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
var request = new NativeRequest(input, init); | ||
var signal = void 0; | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
var request = new NativeRequest(input, init); | ||
if (signal) { | ||
Object.defineProperty(request, 'signal', { | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: signal | ||
}); | ||
} | ||
return request; | ||
@@ -310,2 +333,11 @@ }; | ||
if (init && init.signal) { | ||
// Never pass .signal to the native implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
@@ -312,0 +344,0 @@ return Promise.race([cancellation, realFetch(input, init)]); |
{ | ||
"name": "abortcontroller-polyfill", | ||
"version": "1.2.6", | ||
"version": "1.2.7", | ||
"description": "Polyfill/ponyfill for the AbortController DOM API + optional patching of fetch (stub that calls catch, doesn't actually abort request).", | ||
@@ -27,2 +27,8 @@ "main": "dist/umd-polyfill.js", | ||
"devDependencies": { | ||
"@wdio/cli": "^5.7.1", | ||
"@wdio/jasmine-framework": "^5.7.0", | ||
"@wdio/local-runner": "^5.7.1", | ||
"@wdio/selenium-standalone-service": "^5.7.0", | ||
"@wdio/spec-reporter": "^5.7.0", | ||
"@wdio/sync": "^5.7.1", | ||
"babel-cli": "^6.26.0", | ||
@@ -32,2 +38,3 @@ "babel-core": "^6.26.3", | ||
"babel-preset-env": "^1.7.0", | ||
"detect-browser": "^4.1.0", | ||
"eslint": "^5.9.0", | ||
@@ -37,7 +44,4 @@ "npm-run-all": "^4.1.5", | ||
"rollup-plugin-babel": "^3.0.3", | ||
"wdio-jasmine-framework": "^0.3.7", | ||
"wdio-selenium-standalone-service": "0.0.11", | ||
"wdio-spec-reporter": "^0.1.5", | ||
"webdriverio": "^4.14.0" | ||
"webdriverio": "^5.7.1" | ||
} | ||
} |
@@ -140,2 +140,11 @@ # AbortController polyfill for abortable fetch() | ||
# Using it on Internet Explorer 8 (MSIE8) | ||
The ```abortcontroller-polyfill``` works on Internet Explorer 8. However, since ```github-fetch``` | ||
only supports IE 10+ you need to use the ```fetch-ie8``` npm package instead and also note that IE 8 only | ||
implements ES 3 so you need to use the ```es5-shim``` package (or similar). Finally, just like with | ||
IE 11 you also need to polyfill promises. One caveat is that CORS requests will not work out of the box on IE 8. | ||
Here is a basic example of [abortable fetch running in IE 8](https://github.com/mo/abortcontroller-polyfill-examples/tree/master/plain-javascript-fetch-ie8). | ||
# Contributors | ||
@@ -142,0 +151,0 @@ * [Martin Olsson](https://github.com/mo) |
@@ -23,5 +23,6 @@ import {polyfillNeeded} from './utils.js'; | ||
AbortController: NativeAbortController, | ||
__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL = false, | ||
} = patchTargets; | ||
if (!polyfillNeeded({fetch, Request: NativeRequest, AbortController: NativeAbortController})) { | ||
if (!polyfillNeeded({fetch, Request: NativeRequest, AbortController: NativeAbortController, __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL})) { | ||
return {fetch, Request}; | ||
@@ -42,8 +43,24 @@ } | ||
// TypeError: Cannot set property signal of #<Request> which has only a getter | ||
if (Request && !Request.prototype.hasOwnProperty('signal')) { | ||
if ((Request && !Request.prototype.hasOwnProperty('signal')) || __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
Request = function Request(input, init) { | ||
let request = new NativeRequest(input, init); | ||
let signal; | ||
if (init && init.signal) { | ||
request.signal = init.signal; | ||
signal = init.signal; | ||
// Never pass init.signal to the native Request implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to construct 'Request': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
const request = new NativeRequest(input, init); | ||
if (signal) { | ||
Object.defineProperty(request, 'signal', { | ||
writable: false, | ||
enumerable: false, | ||
configurable: true, | ||
value: signal | ||
}); | ||
} | ||
return request; | ||
@@ -79,2 +96,11 @@ }; | ||
if (init && init.signal) { | ||
// Never pass .signal to the native implementation when the polyfill has | ||
// been installed because if we're running on top of a browser with a | ||
// working native AbortController (i.e. the polyfill was installed due to | ||
// __FORCE_INSTALL_ABORTCONTROLLER_POLYFILL being set), then passing our | ||
// fake AbortSignal to the native fetch will trigger: | ||
// TypeError: Failed to execute 'fetch' on 'Window': member signal is not of type AbortSignal. | ||
delete init.signal; | ||
} | ||
// Return the fastest promise (don't need to wait for request to finish) | ||
@@ -81,0 +107,0 @@ return Promise.race([cancellation, realFetch(input, init)]); |
export function polyfillNeeded(self) { | ||
if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { | ||
console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); | ||
return true; | ||
} | ||
// Note that the "unfetch" minimal fetch polyfill defines fetch() without | ||
@@ -3,0 +8,0 @@ // defining window.Request, and this polyfill need to work on top of unfetch |
71182
1627
163
16