MCPcopy Create free account
hub / github.com/RootbeerComputer/backend-GPT / checkValidServiceWorker

Function checkValidServiceWorker

frontend/src/serviceWorker.js:101–129  ·  view source on GitHub ↗
(swUrl, config)

Source from the content-addressed store, hash-verified

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

Callers 1

registerFunction · 0.85

Calls 1

registerValidSWFunction · 0.85

Tested by

no test coverage detected