(config?: Config)
| 44 | }; |
| 45 | |
| 46 | export function register(config?: Config) { |
| 47 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { |
| 48 | // The URL constructor is available in all browsers that support SW. |
| 49 | const publicUrl = new URL((process as { env: { [key: string]: string } }).env.PUBLIC_URL, window.location.href); |
| 50 | if (publicUrl.origin !== window.location.origin) { |
| 51 | // Our service worker won't work if PUBLIC_URL is on a different origin |
| 52 | // from what our page is served on. This might happen if a CDN is used to |
| 53 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | window.addEventListener('load', () => { |
| 58 | const env = getEnvVariables(); |
| 59 | const swUrl = `${env.NEXT_PUBLIC_PUBLIC_URL}/service-worker.js`; |
| 60 | |
| 61 | if (isLocalhost) { |
| 62 | // This is running on localhost. Let's check if a service worker still exists or not. |
| 63 | checkValidServiceWorker(swUrl, config); |
| 64 | |
| 65 | // Add some additional logging to localhost, pointing developers to the |
| 66 | // service worker/PWA documentation. |
| 67 | navigator.serviceWorker.ready.then(() => { |
| 68 | console.log('This web app is being served cache-first by a service ' + 'worker. To learn more, visit https://bit.ly/CRA-PWA'); |
| 69 | }); |
| 70 | } else { |
| 71 | // Is not localhost. Just register service worker |
| 72 | registerValidSW(swUrl, config); |
| 73 | } |
| 74 | }); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | function registerValidSW(swUrl: string, config?: Config) { |
| 79 | navigator.serviceWorker |
nothing calls this directly
no test coverage detected