UNPKG

abortcontroller-polyfill

Version:

Polyfill/ponyfill for the AbortController DOM API + optional patching of fetch (stub that calls catch, doesn't actually abort request).

31 lines (27 loc) 1.22 kB
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 // defining window.Request, and this polyfill need to work on top of unfetch // so the below feature detection needs the !self.AbortController part. // The Request.prototype check is also needed because Safari versions 11.1.2 // up to and including 12.1.x has a window.AbortController present but still // does NOT correctly implement abortable fetch: // https://bugs.webkit.org/show_bug.cgi?id=174980#c2 return ( (typeof self.Request === 'function' && !self.Request.prototype.hasOwnProperty('signal')) || !self.AbortController ); } export function signalPolyfillNeeded(self) { if (self.__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL) { console.log('__FORCE_INSTALL_ABORTCONTROLLER_POLYFILL=true is set, will force install polyfill'); return true; } return ( !!self.AbortController && typeof self.AbortSignal === 'function' && !self.AbortSignal.prototype.hasOwnProperty('reason') ); }