(swUrl, config)
| 56 | } |
| 57 | |
| 58 | function registerValidSW(swUrl, config) { |
| 59 | navigator.serviceWorker |
| 60 | .register(swUrl) |
| 61 | .then((registration) => { |
| 62 | registration.onupdatefound = () => { |
| 63 | const installingWorker = registration.installing; |
| 64 | if (installingWorker == null) { |
| 65 | return; |
| 66 | } |
| 67 | installingWorker.onstatechange = () => { |
| 68 | if (installingWorker.state === "installed") { |
| 69 | if (navigator.serviceWorker.controller) { |
| 70 | // At this point, the updated precached content has been fetched, |
| 71 | // but the previous service worker will still serve the older |
| 72 | // content until all client tabs are closed. |
| 73 | console.log( |
| 74 | "New content is available and will be used when all " + |
| 75 | "tabs for this page are closed. See https://cra.link/PWA." |
| 76 | ); |
| 77 | |
| 78 | // Execute callback |
| 79 | if (config && config.onUpdate) { |
| 80 | config.onUpdate(registration); |
| 81 | } |
| 82 | } else { |
| 83 | // At this point, everything has been precached. |
| 84 | // It's the perfect time to display a |
| 85 | // "Content is cached for offline use." message. |
| 86 | console.log("Content is cached for offline use."); |
| 87 | |
| 88 | // Execute callback |
| 89 | if (config && config.onSuccess) { |
| 90 | config.onSuccess(registration); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | }; |
| 95 | }; |
| 96 | }) |
| 97 | .catch((error) => { |
| 98 | console.error("Error during service worker registration:", error); |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | function checkValidServiceWorker(swUrl, config) { |
| 103 | // Check if the service worker can be found. If it can't reload the page. |
no outgoing calls
no test coverage detected