(swUrl, config)
| 97 | } |
| 98 | |
| 99 | function checkValidServiceWorker(swUrl, config) { |
| 100 | // Check if the service worker can be found. If it can't reload the page. |
| 101 | fetch(swUrl, { |
| 102 | headers: { 'Service-Worker': 'script' }, |
| 103 | }) |
| 104 | .then((response) => { |
| 105 | // Ensure service worker exists, and that we really are getting a JS file. |
| 106 | const contentType = response.headers.get('content-type'); |
| 107 | if ( |
| 108 | response.status === 404 || |
| 109 | (contentType != null && contentType.indexOf('javascript') === -1) |
| 110 | ) { |
| 111 | // No service worker found. Probably a different app. Reload the page. |
| 112 | navigator.serviceWorker.ready.then((registration) => { |
| 113 | registration.unregister().then(() => { |
| 114 | window.location.reload(); |
| 115 | }); |
| 116 | }); |
| 117 | } else { |
| 118 | // Service worker found. Proceed as normal. |
| 119 | registerValidSW(swUrl, config); |
| 120 | } |
| 121 | }) |
| 122 | .catch(() => { |
| 123 | console.log('No internet connection found. App is running in offline mode.'); |
| 124 | }); |
| 125 | } |
| 126 | |
| 127 | export function unregister() { |
| 128 | if ('serviceWorker' in navigator) { |
no test coverage detected