Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
window.navigator.serviceWorker.register = (...args) => {
const url = args[0];
if (typeof url === 'string') {
if (WindowSandbox._isSecureOrigin(url)) {
// NOTE: We cannot create an instance of the DOMException in the Android 6.0 and in the Edge 17 browsers.
// The 'TypeError: Illegal constructor' error is raised if we try to call the constructor.
return Promise.reject(isAndroid || isMSEdge && browserVersion >= 17
? new Error('Only secure origins are allowed.')
: new DOMException('Only secure origins are allowed.', 'SecurityError'));
}
args[0] = getProxyUrl(url, { resourceType: stringifyResourceType({ isScript: true }) });
}
if (args[1] && typeof args[1].scope === 'string') {
args[1].scope = getProxyUrl(args[1].scope, {
resourceType: stringifyResourceType({ isScript: true })
});
}
return nativeMethods.registerServiceWorker.apply(window.navigator.serviceWorker, args);
};
}
.catch(err => {
if (isRejectingAllowed)
return Promise.reject(err);
return createUnresolvablePromise();
});
}