diff --git a/ProjectHeads/SingleComponent/Wasm/wwwroot/SharedArrayBufferServiceWorker.js b/ProjectHeads/SingleComponent/Wasm/wwwroot/SharedArrayBufferServiceWorker.js new file mode 100644 index 00000000..d8f6b3c2 --- /dev/null +++ b/ProjectHeads/SingleComponent/Wasm/wwwroot/SharedArrayBufferServiceWorker.js @@ -0,0 +1,39 @@ +// From https://dev.to/stefnotch/enabling-coop-coep-without-touching-the-server-2d3n + +self.addEventListener("install", function () { + self.skipWaiting(); +}); + +self.addEventListener("activate", (event) => { + event.waitUntil(self.clients.claim()); +}); + +self.addEventListener("fetch", function (event) { + if (event.request.cache === "only-if-cached" && event.request.mode !== "same-origin") { + return; + } + + event.respondWith( + fetch(event.request) + .then(function (response) { + // It seems like we only need to set the headers for index.html + // If you want to be on the safe side, comment this out + // if (!response.url.includes("index.html")) return response; + + const newHeaders = new Headers(response.headers); + newHeaders.set("Cross-Origin-Embedder-Policy", "credentialless"); + newHeaders.set("Cross-Origin-Opener-Policy", "same-origin"); + + const moddedResponse = new Response(response.body, { + status: response.status, + statusText: response.statusText, + headers: newHeaders, + }); + + return moddedResponse; + }) + .catch(function (e) { + console.error(e); + }) + ); +}); diff --git a/ProjectHeads/SingleComponent/Wasm/wwwroot/index.html b/ProjectHeads/SingleComponent/Wasm/wwwroot/index.html new file mode 100644 index 00000000..095835f0 --- /dev/null +++ b/ProjectHeads/SingleComponent/Wasm/wwwroot/index.html @@ -0,0 +1,38 @@ + + + + + + + + + + + + + $(ADDITIONAL_CSS) + $(ADDITIONAL_HEAD) + + +
+
+ + + + + + +
+
+ + + \ No newline at end of file diff --git a/ProjectHeads/SingleComponent/Wasm/wwwroot/scripts/EnableSharedArrayBuffer.js b/ProjectHeads/SingleComponent/Wasm/wwwroot/scripts/EnableSharedArrayBuffer.js new file mode 100644 index 00000000..239087eb --- /dev/null +++ b/ProjectHeads/SingleComponent/Wasm/wwwroot/scripts/EnableSharedArrayBuffer.js @@ -0,0 +1,19 @@ +// From https://dev.to/stefnotch/enabling-coop-coep-without-touching-the-server-2d3n + +if ("serviceWorker" in navigator) { + // Register service worker + navigator.serviceWorker.register(new URL("SharedArrayBufferServiceWorker.js", window.location.href)).then( + function (registration) { + console.log("COOP/COEP Service Worker registered", registration.scope); + // If the registration is active, but it's not controlling the page + if (registration.active && !navigator.serviceWorker.controller) { + window.location.reload(); + } + }, + function (err) { + console.log("COOP/COEP Service Worker failed to register", err); + } + ); +} else { + console.warn("Cannot register a service worker"); +}