SharedArrayBuffer
SharedArrayBuffer is an object that holds a fixed-length binary buffer. You can pass around comparably longer data with SharedArrayBuffer between agents (i.e., main thread and worker.) A change in one ShardArrayBuffer will reflect on the other side.
const sab = new SharedArrayBuffer(1024)
worker.postMessage(sab)
The Spectre vulnerability seized ShardArrayBuffer in 2018, and since 2020, ShardArrayBuffer requires a Secure Context to run.
For the host document, I need two headers to enable ShardArrayBuffer.
Cross-Origin-Opener-Policy
withsame-origin
as value (protects your origin from attackers)Cross-Origin-Embedder-Policy
withrequire-corp
as value (protects victims from your origin)