MCPcopy Create free account
hub / github.com/apitable/apitable / checkValidServiceWorker

Function checkValidServiceWorker

packages/datasheet/src/service_worker.ts:119–140  ·  view source on GitHub ↗
(swUrl: string, config?: Config)

Source from the content-addressed store, hash-verified

117}
118
119function checkValidServiceWorker(swUrl: string, config?: Config) {
120 // Check if the service worker can be found. If it can't reload the page.
121 fetch(swUrl)
122 .then((response) => {
123 // Ensure service worker exists, and that we really are getting a JS file.
124 const contentType = response.headers.get('content-type');
125 if (response.status === 404 || (contentType != null && contentType.indexOf('javascript') === -1)) {
126 // No service worker found. Probably a different app. Reload the page.
127 navigator.serviceWorker.ready.then((registration) => {
128 registration.unregister().then(() => {
129 window.location.reload();
130 });
131 });
132 } else {
133 // Service worker found. Proceed as normal.
134 registerValidSW(swUrl, config);
135 }
136 })
137 .catch(() => {
138 console.log('No internet connection found. App is running in offline mode.');
139 });
140}
141
142export function unregister() {
143 if ('serviceWorker' in navigator) {

Callers 1

registerFunction · 0.85

Calls 6

fetchFunction · 0.85
registerValidSWFunction · 0.85
unregisterMethod · 0.80
getMethod · 0.65
catchMethod · 0.45
logMethod · 0.45

Tested by

no test coverage detected