FTXUI/examples/sw.js

26 lines
750 B
JavaScript
Raw Permalink Normal View History

// 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")) {
return;
2022-07-10 01:58:11 +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;
})());
});