I'm currently working on a project where I also encountered the SharedArrayBuffer issue when integrating ffmpeg-wasm.
This first snippet from cross origin resource policy issue when playing files from s3 on deployed app solved my problem. This would go in your server.js (note that the sequence is important, set headers before express.static):
app.use((req, res, next) => {
res.header("Cross-Origin-Embedder-Policy", "require-corp");
res.header("Cross-Origin-Opener-Policy", "same-origin");
next();
});
app.use(express.static(...));
Alternatively:
const customHeaders = (res, path, stat) => {
res.append("Cross-Origin-Embedder-Policy", "require-corp");
res.append("Cross-Origin-Opener-Policy", "same-origin");
}
app.use(express.static(...), {
setHeaders: customHeaders
});
Note that there are some issues with this approach:
- SharedArrayBuffer is not supported in Safari and some other browsers, see https://caniuse.com/sharedarraybuffer
- All cross-origin loads from the browser will fail, for example external scripts (e.g. Analytics) or image loads from other domains