FTXUI/examples/sw.js
2022-07-09 18:51:35 +02:00

24 lines
699 B
JavaScript

// sw.js
self.addEventListener("install", () => self.skipWaiting());
self.addEventListener("activate", e => e.waitUntil(self.clients.claim()));
self.addEventListener("fetch", e => {
if (e.request.mode != 'navigate')
return;
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;
})());
});