Loading...
window.addEventListener('storage', (e) => {
if (e.key === 'logout') signOut();
});
localStorage.setItem('logout', Date.now());const channel = new BroadcastChannel('auth');
channel.onmessage = (e) => {
if (e.data.type === 'logout') signOut();
};
channel.postMessage({ type: 'logout' });BroadcastChannel sends structured messages to same-origin tabs directly, without abusing storage writes.
close() when the page or component no longer needs it.No, the sending channel object does not get its own message, but other BroadcastChannel objects with the same name do, even in the same tab.
No, it only connects windows, tabs, iframes and workers of the same origin. Use window.postMessage() for cross-origin messages.