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

BroadcastChannel — Cross-Tab Messaging

JavaScript HTML5 Intermediate
debt(d7/e3/b3/t5)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate no automated detection ('automated: no'), and the code_pattern is simply 'BroadcastChannel'. Misuses such as forgetting channel.close(), expecting self-receipt, or cross-origin confusion are silent at runtime — no linter or compiler flags them. Testing or manual review is required to catch these.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates adding close() in cleanup and adjusting message-receipt expectations — small, localised changes within the component that uses BroadcastChannel. No cross-cutting refactor is needed; fixes are confined to the relevant tab/page context.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). BroadcastChannel usage is scoped to the web context and typically confined to specific feature areas (auth state, theme, cart). It does not impose a structural weight on the rest of the codebase — only the components using it pay the cost of managing channel lifecycle.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field explicitly states that developers expect the sender tab to receive its own messages — it doesn't. This is a documented gotcha that most developers hit when first using the API, contradicting the intuition that 'broadcast' means 'everyone including me'. Not catastrophic, but a clear and common surprise.

About DEBT scoring →

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 53
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 1 ping W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 1 ping S 1 ping M 1 ping T 4 pings W 1 ping T 2 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
Sogou 1
Scrapy 8 Amazonbot 7 Perplexity 5 Unknown AI 4 Google 4 ChatGPT 3 Ahrefs 3 SEMrush 3 Majestic 1 Claude 1 Meta AI 1 Sogou 1
crawler 37 crawler_json 2 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