(config)
| 19 | ); |
| 20 | |
| 21 | export function register(config) { |
| 22 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { |
| 23 | // The URL constructor is available in all browsers that support SW. |
| 24 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); |
| 25 | if (publicUrl.origin !== window.location.origin) { |
| 26 | // Our service worker won't work if PUBLIC_URL is on a different origin |
| 27 | // from what our page is served on. This might happen if a CDN is used to |
| 28 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | window.addEventListener('load', () => { |
| 33 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; |
| 34 | |
| 35 | if (isLocalhost) { |
| 36 | // This is running on localhost. Let's check if a service worker still exists or not. |
| 37 | checkValidServiceWorker(swUrl, config); |
| 38 | |
| 39 | // Add some additional logging to localhost, pointing developers to the |
| 40 | // service worker/PWA documentation. |
| 41 | navigator.serviceWorker.ready.then(() => { |
| 42 | console.log( |
| 43 | 'This web app is being served cache-first by a service ' + |
| 44 | 'worker. To learn more, visit https://cra.link/PWA' |
| 45 | ); |
| 46 | }); |
| 47 | } else { |
| 48 | // Is not localhost. Just register service worker |
| 49 | registerValidSW(swUrl, config); |
| 50 | } |
| 51 | }); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | function registerValidSW(swUrl, config) { |
| 56 | navigator.serviceWorker |
nothing calls this directly
no test coverage detected