MCPcopy Create free account
hub / github.com/MegEngine/MegFlow / checkValidServiceWorker

Function checkValidServiceWorker

flow-debugger/debugger-ui/src/serviceWorker.js:101–130  ·  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 &&
112 contentType.indexOf("javascript") === -1)
113 ) {
114 // No service worker found. Probably a different app. Reload the page.
115 navigator.serviceWorker.ready.then((registration) => {
116 registration.unregister().then(() => {
117 window.location.reload();
118 });
119 });
120 } else {
121 // Service worker found. Proceed as normal.
122 registerValidSW(swUrl, config);
123 }
124 })
125 .catch(() => {
126 console.log(
127 "No internet connection found. App is running in offline mode."
128 );
129 });
130}
131
132export function unregister() {
133 if ("serviceWorker" in navigator) {

Callers 1

registerFunction · 0.85

Calls 2

registerValidSWFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected