mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 11:35:04 +01:00
log non-network errors in service worker to diagnose #187
This commit is contained in:
parent
9708e394a0
commit
85ba1676e5
@ -86,22 +86,29 @@ function isCacheableThumbnail(url) {
|
|||||||
|
|
||||||
const baseURL = new URL(self.registration.scope);
|
const baseURL = new URL(self.registration.scope);
|
||||||
async function handleRequest(request) {
|
async function handleRequest(request) {
|
||||||
const url = new URL(request.url);
|
try {
|
||||||
if (url.origin === baseURL.origin && url.pathname === baseURL.pathname) {
|
const url = new URL(request.url);
|
||||||
request = new Request(new URL("index.html", baseURL.href));
|
if (url.origin === baseURL.origin && url.pathname === baseURL.pathname) {
|
||||||
}
|
request = new Request(new URL("index.html", baseURL.href));
|
||||||
let response = await readCache(request);
|
|
||||||
if (!response) {
|
|
||||||
// use cors so the resource in the cache isn't opaque and uses up to 7mb
|
|
||||||
// https://developers.google.com/web/tools/chrome-devtools/progressive-web-apps?utm_source=devtools#opaque-responses
|
|
||||||
if (isCacheableThumbnail(url)) {
|
|
||||||
response = await fetch(request, {mode: "cors", credentials: "omit"});
|
|
||||||
} else {
|
|
||||||
response = await fetch(request);
|
|
||||||
}
|
}
|
||||||
await updateCache(request, response);
|
let response = await readCache(request);
|
||||||
|
if (!response) {
|
||||||
|
// use cors so the resource in the cache isn't opaque and uses up to 7mb
|
||||||
|
// https://developers.google.com/web/tools/chrome-devtools/progressive-web-apps?utm_source=devtools#opaque-responses
|
||||||
|
if (isCacheableThumbnail(url)) {
|
||||||
|
response = await fetch(request, {mode: "cors", credentials: "omit"});
|
||||||
|
} else {
|
||||||
|
response = await fetch(request);
|
||||||
|
}
|
||||||
|
await updateCache(request, response);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (err) {
|
||||||
|
if (!(err instanceof TypeError)) {
|
||||||
|
console.error("error in service worker", err);
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function updateCache(request, response) {
|
async function updateCache(request, response) {
|
||||||
|
Loading…
Reference in New Issue
Block a user