phanpy/src/polyfills.js

25 lines
707 B
JavaScript
Raw Normal View History

2024-06-14 03:34:50 +03:00
// AbortSignal.timeout polyfill
// Temporary fix from https://github.com/mo/abortcontroller-polyfill/issues/73#issuecomment-1541180943
// Incorrect implementation, but should be good enough for now
if ('AbortSignal' in window) {
AbortSignal.timeout =
AbortSignal.timeout ||
((duration) => {
const controller = new AbortController();
setTimeout(() => controller.abort(), duration);
return controller.signal;
});
}
// URL.parse() polyfill
if ('URL' in window && typeof URL.parse !== 'function') {
URL.parse = function (url, base) {
if (!url) return null;
try {
return base ? new URL(url, base) : new URL(url);
} catch (e) {
return null;
}
};
}