0
The service worker that I will show below works well in google Chrome, but when I am using the mozila firefoz 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 have the firefox audience too. Tó using locally for service worker testing, so 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));
}
});
Someone could help me with this mistake?