(swUrl)
| 44 | } |
| 45 | |
| 46 | function registerValidSW(swUrl) { |
| 47 | navigator.serviceWorker |
| 48 | .register(swUrl) |
| 49 | .then(registration => { |
| 50 | registration.onupdatefound = () => { |
| 51 | const installingWorker = registration.installing; |
| 52 | installingWorker.onstatechange = () => { |
| 53 | if (installingWorker.state === 'installed') { |
| 54 | if (navigator.serviceWorker.controller) { |
| 55 | // At this point, the old content will have been purged and |
| 56 | // the fresh content will have been added to the cache. |
| 57 | // It's the perfect time to display a "New content is |
| 58 | // available; please refresh." message in your web app. |
| 59 | console.log('New content is available; please refresh.'); |
| 60 | } else { |
| 61 | // At this point, everything has been precached. |
| 62 | // It's the perfect time to display a |
| 63 | // "Content is cached for offline use." message. |
| 64 | console.log('Content is cached for offline use.'); |
| 65 | } |
| 66 | } |
| 67 | }; |
| 68 | }; |
| 69 | }) |
| 70 | .catch(error => { |
| 71 | console.error('Error during service worker registration:', error); |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | function checkValidServiceWorker(swUrl) { |
| 76 | // Check if the service worker can be found. If it can't reload the page. |
no test coverage detected