The service worker I'm going to show below works fine in google chrome, but when I'm using mozilla firefoz it returns the error:
Failed to load 'http://127.0.0.1:8000/#/'. A ServiceWorker passed a promise to FetchEvent.respondWith() that resolved with non-Response value 'undefined'.
This way I get my site limited to chrome. I would like help to be able to have the firefox public as well. Using locally for service worker testing, so it is 127.0.0.1:8000.
self.addEventListener("fetch", function(e) {
const url = new URL(e.request.url);
if (
url.hostname === "https://meu.site.com" ||
url.hostname === "cdnjs.cloudflare.com" ||
url.hostname === "fonts.googleapis.com" ||
url.hostname === "https://meu.site.homologacao.com/"
) {
e.respondWith(
caches.match(e.request).then(function(response) {
var fetchRequest = e.request.clone();
return fetch(fetchRequest)
.then(function(response) {
if (
response ||
response.status === 200 ||
response.type === "basic"
) {
console.log("OnLine");
return response;
} else {
console.log("OffLine");
var responseToCache = response.clone();
caches.open(STATIC_CACHE_NAME).then(function(cache) {
cache.put(e.request, responseToCache);
});
return response;
}
})
.catch(error => {
console.log("Fetch failed; returning offline page instead.", error);
return caches.match(OFFLINE_URL);
});
})
);
} else if (CACHE_APP.indexOf(url.pathname) !== -1) {
e.respondWith(caches.match(e.request));
}
});
Can anyone help me with this error?