wingify / across-tabs

Easy communication between cross-origin browser tabs. Simplified "CORS"ing!

Home Page:https://engineering.wingify.com/across-tabs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement Broadcast Channel API

filips123 opened this issue · comments

The Broadcast Channel API allows simple communication between browsing contexts (that is windows, tabs, frames, or iframes) with the same origin (usually pages from the same site).

It's downsides are that is only works in modern browsers and with same origin.
Maybe you could look to it, use it for same origin communication and fallback when it is not available (old browser or cross origin).


Also, add support to attach any tab (not just those that parent opens) to channel. Something like in Broadcast Channel API, but for cross origin.

I've created library with very simple API sysend.js here is demo https://jcubic.pl/sysend.php you don't need to attach anything only call on() to add handler or broadcast() to send the event to different tab/window. I've used iframe proxy to allow cross-origin. and I've recently added broadcast channel API if it's not supported it use localStorage.

@filips123 This library was made to tackle cross-origin challenges only. For same-origin, there are simple ways to do it(localStorage/cookies). Also, postMessage API can be directly used just like Broadcast API. The only benefit of Broadcast API is that we no longer have to maintain references of iframes/windows to send/receive messages. Otherwise, there's no particular benefit of using it.

Closing this issue since this library is specifically for cross-origin and postMessage is already used for doing so.

I don't know about current solution but localStorage and Cookies require to serialize data to string and Channel can send javascript object without serialization.