MCPcopy
hub / github.com/summitech/gitexplorer / checkValidServiceWorker

Function checkValidServiceWorker

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

Source from the content-addressed store, hash-verified

96}
97
98function checkValidServiceWorker(swUrl, config) {
99 // Check if the service worker can be found. If it can't reload the page.
100 fetch(swUrl)
101 .then((response) => {
102 // Ensure service worker exists, and that we really are getting a JS file.
103 if (
104 response.status === 404
105 || response.headers.get('content-type').indexOf('javascript') === -1
106 ) {
107 // No service worker found. Probably a different app. Reload the page.
108 navigator.serviceWorker.ready.then((registration) => {
109 registration.unregister().then(() => {
110 window.location.reload();
111 });
112 });
113 } else {
114 // Service worker found. Proceed as normal.
115 registerValidSW(swUrl, config);
116 }
117 })
118 .catch(() => {
119 console.log(
120 'No internet connection found. App is running in offline mode.'
121 );
122 });
123}
124
125export function unregister() {
126 if ('serviceWorker' in navigator) {

Callers 1

registerFunction · 0.85

Calls 1

registerValidSWFunction · 0.85

Tested by

no test coverage detected