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

Function checkValidServiceWorker

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

Source from the content-addressed store, hash-verified

73}
74
75function checkValidServiceWorker(swUrl) {
76 // Check if the service worker can be found. If it can't reload the page.
77 fetch(swUrl)
78 .then(response => {
79 // Ensure service worker exists, and that we really are getting a JS file.
80 if (
81 response.status === 404 ||
82 response.headers.get('content-type').indexOf('javascript') === -1
83 ) {
84 // No service worker found. Probably a different app. Reload the page.
85 navigator.serviceWorker.ready.then(registration => {
86 registration.unregister().then(() => {
87 window.location.reload();
88 });
89 });
90 } else {
91 // Service worker found. Proceed as normal.
92 registerValidSW(swUrl);
93 }
94 })
95 .catch(() => {
96 console.log(
97 'No internet connection found. App is running in offline mode.'
98 );
99 });
100}
101
102export function unregister() {
103 if ('serviceWorker' in navigator) {

Callers 1

registerFunction · 0.85

Calls 2

registerValidSWFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected