2022-07-10 00:39:01 +08:00
|
|
|
// sw.js
|
|
|
|
self.addEventListener("install", () => self.skipWaiting());
|
|
|
|
self.addEventListener("activate", e => e.waitUntil(self.clients.claim()));
|
|
|
|
self.addEventListener("fetch", e => {
|
2022-07-10 01:58:11 +08:00
|
|
|
if (e.request.mode != 'navigate' &&
|
|
|
|
!e.request.url.includes(".worker.js")) {
|
2022-07-10 00:39:01 +08:00
|
|
|
return;
|
2022-07-10 01:58:11 +08:00
|
|
|
}
|
2022-07-10 00:39:01 +08:00
|
|
|
|
|
|
|
e.respondWith((async () => {
|
|
|
|
const response = await fetch(e.request);
|
|
|
|
|
|
|
|
const newHeaders = new Headers(response.headers);
|
|
|
|
newHeaders.set("Cross-Origin-Embedder-Policy", "require-corp");
|
|
|
|
newHeaders.set("Cross-Origin-Opener-Policy", "same-origin");
|
|
|
|
|
|
|
|
const moddedResponse = new Response(response.body, {
|
|
|
|
status: response.status,
|
|
|
|
statusText: response.statusText,
|
|
|
|
headers: newHeaders,
|
|
|
|
});
|
|
|
|
|
|
|
|
return moddedResponse;
|
|
|
|
})());
|
|
|
|
});
|