Cross origin sharedmemory atomic int64

Assume:

  1. We control foo.com and bar.com

  2. foo.com loads an iframe, which loads bar.com

  3. foo.com and bar.com are both running Rust/wasm32 code we control

  4. this is all running in latest Chrome

Question: Is it possible to setup a shared memory, between foo.com and bar.com, where we have an atomic int64 in the shared memory ?

XY problem: I have Rust/wasm32 code running in different iframes; and I want a simple way, without going into vector clocks, of defining a total order for events that happen in different iframes.

I'd prefer to use shared memory instead of paying the price of postMessage/onMessage constantly.

Thanks!

I don't believe there's any way to directly share memory between multiple iframes even if they have the same origin.

You can use a SharedWorker in the same origin case to have a memory region that is accessible from multiple iframes, but you still have to communicate with the worker via messages from the iframes.

You need

  • a SharedArrayBuffer
  • access to the iframe window object to send a postMessage.
  • set HTTP headers to disable isolation between them so they can use shared memory

Once you have shared a buffer between windows you pass it to wasm.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.