(swUrl: string, config?: Config)
| 117 | } |
| 118 | |
| 119 | function checkValidServiceWorker(swUrl: string, config?: Config) { |
| 120 | // Check if the service worker can be found. If it can't reload the page. |
| 121 | fetch(swUrl) |
| 122 | .then((response) => { |
| 123 | // Ensure service worker exists, and that we really are getting a JS file. |
| 124 | const contentType = response.headers.get('content-type'); |
| 125 | if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) { |
| 126 | // No service worker found. Probably a different app. Reload the page. |
| 127 | navigator.serviceWorker.ready.then((registration) => { |
| 128 | registration.unregister().then(() => { |
| 129 | window.location.reload(); |
| 130 | }); |
| 131 | }); |
| 132 | } else { |
| 133 | // Service worker found. Proceed as normal. |
| 134 | registerValidSW(swUrl, config); |
| 135 | } |
| 136 | }) |
| 137 | .catch(() => { |
| 138 | console.log('No internet connection found. App is running in offline mode.'); |
| 139 | }); |
| 140 | } |
| 141 | |
| 142 | export function unregister() { |
| 143 | if ('serviceWorker' in navigator) { |
no test coverage detected