()
| 19 | ); |
| 20 | |
| 21 | export default function register () { |
| 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); |
| 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/facebookincubator/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. Lets check if a service worker still exists or not. |
| 37 | checkValidServiceWorker(swUrl); |
| 38 | } else { |
| 39 | // Is not local host. Just register service worker |
| 40 | registerValidSW(swUrl); |
| 41 | } |
| 42 | }); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | function registerValidSW (swUrl) { |
| 47 | navigator.serviceWorker |
nothing calls this directly
no test coverage detected