Favorites

JavaScript SharedArrayBuffer Object

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
SharedArrayBuffer
JavaScript Structured Data · ConstructorThis object is supported by all modern browsers.
Updated 28th November 2026

A SharedArrayBuffer is a block of binary memory that can be shared between the main thread and web workers, so they can work on the same data at the same time.

Description

A SharedArrayBuffer is like an ArrayBuffer, but its memory can be shared between threads: when you post it to a web worker, both sides see the same bytes rather than a copy. Use Atomics to read and write it safely when several threads are involved.

For security reasons, browsers only make SharedArrayBuffer available on pages that are cross-origin isolated, which requires the Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp HTTP headers. You can check with self.crossOriginIsolated.

When several threads read and write the same memory, ordinary reads and writes can see partially updated data or lose changes, so all access to shared values that change should go through Atomics. Atomics.wait() and Atomics.notify() let workers sleep until another thread signals them, which is the building block for locks and queues.

Shared memory is mostly used by performance-critical code, such as WebAssembly applications, games and audio processing, that needs several threads working on the same data. For most applications, sending copies of data between threads with postMessage() is simpler and safe.

Creating

new SharedArrayBuffer(byteLength)

Example

console.log('crossOriginIsolated:', self.crossOriginIsolated);
if (typeof SharedArrayBuffer !== 'undefined') {
  const shared = new SharedArrayBuffer(16);
  const counter = new Int32Array(shared);
  Atomics.add(counter, 0, 5);
  console.log(Atomics.load(counter, 0));
} else {
  console.log('SharedArrayBuffer needs cross-origin isolation here');
}

Browser Support

The following information will show you the current browser support for the SharedArrayBuffer object. Hover over a browser icon to see the version that first introduced support for this object.

This object is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee