You can get SharedArrayBuffer to work by setting the required COOP and COEP headers through a service worker (even on Github Pages). This blogpost will explain the basics and show you how.
Essentially, the idea is to
- when the page gets loaded for the first time, we register the worker
- then we reload the page
- and finally, now that the worker is controlling everything, every request will now have the appropriate headers set
The service worker which does that has to contain something along the lines of
// sw.js
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) {
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;
})
.catch(function (e) {
console.error(e);
})
);
});
I created a small library just now to make it easier: coi-serviceworker.