MCPcopy
hub / github.com/remy/jsconsole / registerValidSW

Function registerValidSW

src/registerServiceWorker.js:46–73  ·  view source on GitHub ↗
(swUrl)

Source from the content-addressed store, hash-verified

44}
45
46function 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
75function checkValidServiceWorker(swUrl) {
76 // Check if the service worker can be found. If it can't reload the page.

Callers 2

registerFunction · 0.85
checkValidServiceWorkerFunction · 0.85

Calls 1

logMethod · 0.80

Tested by

no test coverage detected