If you are using feature detection with SharedArrayBuffer
objects today you are likely impacted by upcoming changes to shared memory. In particular, you can no longer assume that if you have access to a SharedArrayBuffer
object you can also use it with postMessage()
. Detecting if SharedArrayBuffer
objects are exposed can be done through the following code:
if (self.SharedArrayBuffer) {
// SharedArrayBuffer objects are available.
}
Detecting if shared memory is possible by using SharedArrayBuffer
objects in combination with postMessage()
and workers can be done through the following code:
if (self.crossOriginIsolated) {
// Passing SharedArrayBuffer objects to postMessage() will succeed.
}
Please update your code accordingly!
(As indicated in the aforelinked changes document obtaining a cross-origin isolated environment (i.e., one wherein self.crossOriginIsolated
returns true) requires setting two headers and a secure context. Simply put, the Cross-Origin-Opener-Policy
header to isolate yourself from attackers and the Cross-Origin-Embedder-Policy
header to isolate yourself from victims.)