MCPcopy
hub / github.com/mdnice/markdown-resume / registerValidSW

Function registerValidSW

src/serviceWorker.js:57–99  ·  view source on GitHub ↗
(swUrl, config)

Source from the content-addressed store, hash-verified

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

Callers 2

registerFunction · 0.85
checkValidServiceWorkerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected