diff --git a/packages/react-scripts/template/src/registerServiceWorker.js b/packages/react-scripts/template/src/registerServiceWorker.js index 4a3ccf02124..41308467b2e 100644 --- a/packages/react-scripts/template/src/registerServiceWorker.js +++ b/packages/react-scripts/template/src/registerServiceWorker.js @@ -21,7 +21,7 @@ const isLocalhost = Boolean( export default function register() { if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location); + const publicUrl = new window.URL(process.env.PUBLIC_URL, window.location); if (publicUrl.origin !== window.location.origin) { // Our service worker won't work if PUBLIC_URL is on a different origin // from what our page is served on. This might happen if a CDN is used to @@ -74,7 +74,7 @@ function registerValidSW(swUrl) { function checkValidServiceWorker(swUrl) { // Check if the service worker can be found. If it can't reload the page. - fetch(swUrl) + window.fetch(swUrl) .then(response => { // Ensure service worker exists, and that we really are getting a JS file. if ( @@ -100,8 +100,8 @@ function checkValidServiceWorker(swUrl) { } export function unregister() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready.then(registration => { + if ('serviceWorker' in window.navigator) { + window.navigator.serviceWorker.ready.then(registration => { registration.unregister(); }); }