10LOC

#messaging

Web Platformintermediate

BroadcastChannel for cross-tab messaging

const channel = new BroadcastChannel("auth");

export const broadcastLogout = (reason: string) => channel.postMessage({ type: "logout", reason });

channel.addEventListener("message", (event: MessageEvent<{ type: string; reason: string }>) => {

Log out in one tab and every other open tab reacts instantly, with a plain publish/subscribe API and no polling or server round trip.