← CodeClarityLab Home
Browse by Category
+ added · updated 7d
← Back to glossary

BroadcastChannel — Cross-Tab Messaging

javascript HTML5 Intermediate

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();

Added 23 Mar 2026
Edited 5 Apr 2026
Views 27
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
2 pings W 0 pings T 1 ping F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 1 ping F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 6 Perplexity 5 Unknown AI 4 Google 3 ChatGPT 1 Majestic 1 Ahrefs 1
crawler 19 pre-tracking 2
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

✓ schema.org compliant