BroadcastChannel — Cross-Tab Messaging
TL;DR
BroadcastChannel allows same-origin pages/tabs to communicate — post a message on one tab, receive it in all others — without a server or service worker.
Explanation
BroadcastChannel(name) creates a named channel. Messages posted with channel.postMessage(data) are received by all other pages on the same origin subscribed to the same channel name — not the sender itself. Data is structured-cloned (supports objects, ArrayBuffers, not functions). Use cases: tab synchronisation (logout across all tabs), shared state updates, cross-tab notifications. Close with channel.close() when done. Compared to Service Worker messaging: simpler, no SW required. Compared to localStorage events: more reliable, supports rich data types.
Common Misconception
✗ BroadcastChannel sends messages to the current tab too — it only sends to OTHER pages/tabs on the same origin with the same channel name.
Why It Matters
BroadcastChannel enables real-time synchronisation across browser tabs without a server round-trip — essential for single-sign-out and shared UI state.
Common Mistakes
- Not calling channel.close() — channels persist as long as the page lives.
- Expecting the sender to receive its own messages — it doesn't.
- Using BroadcastChannel across different origins — blocked by same-origin policy.
Code Examples
✗ Vulnerable
// localStorage events — limited to string values:
localStorage.setItem('logout', Date.now());
window.addEventListener('storage', e => {
if (e.key === 'logout') logout();
});
✓ Fixed
const channel = new BroadcastChannel('auth');
// Send logout to all other tabs:
channel.postMessage({ type: 'logout', timestamp: Date.now() });
// Receive:
channel.onmessage = ({ data }) => {
if (data.type === 'logout') logout();
};
// Cleanup:
channel.close();
Tags
🤝 Adopt this term
£79/year · your link shown here
Added
23 Mar 2026
Edited
5 Apr 2026
Views
27
🤖 AI Guestbook educational data only
|
|
Last 30 days
Agents 0
No pings yet today
No pings yesterday
Amazonbot 6
Perplexity 5
Unknown AI 4
Google 3
ChatGPT 1
Majestic 1
Ahrefs 1
Also referenced
How they use it
crawler 19
pre-tracking 2
Related categories
⚡
DEV INTEL
Tools & Severity
🔵 Info
⚙ Fix effort: Low
⚡ Quick Fix
Use BroadcastChannel for cross-tab sync (auth state, theme changes, cart updates). Always close() the channel in cleanup.
📦 Applies To
javascript HTML5
web
cli
🔗 Prerequisites
🔍 Detection Hints
BroadcastChannel
Auto-detectable:
✗ No
🤖 AI Agent
Confidence: Low
False Positives: High
✗ Manual fix
Fix: Low
Context: File