DEV Community

Discussion on: Cross Tab Communication with Javascript

Collapse
vince_tblt profile image
Vincent Thibault

Some other possibilities :

  • SessionStorage (same than localStorage but w/o persistence)
  • SharedWorker (oups, deprecated !)
  • ServiceWorker (postMessage and loop other all opened window instances to broadcast message).
  • If all tabs are attached because opened from the same source page (const child = window.open()), you can communicate using the instance and window.opener.
Collapse
mvasigh profile image
Mehdi Vasigh • Edited

SharedWorker is not deprecated, right? MDN says nothing about that. It's probably the most well-supported way of doing this although BroadcastChannel has much better DX.

Also the npm package broadcast-channel does this with fallbacks to non-native BroadcastChannel alternatives i.e. localStorage (for IE) and idb.

Collapse
vince_tblt profile image
Vincent Thibault

SharedWorker was flagged “removed” from WebKit spec and IE didn’t plan to implement it.
The main reason for the dismiss is the ServiceWorker API that appeared soon after and can handle all the SharedWorker API.

Thread Thread
mvasigh profile image
Mehdi Vasigh

Ah I see, TIL. Thanks!