- BroadcastChannel
-
A same-origin named messaging bus. Any eligible
browsing context or worker that opens
a channel with the same name can send and receive
structured-clone messages. It is
pub/sub only — not shared memory and not a shared
process.
- Channel name
-
The string passed to
new BroadcastChannel(name). Only
objects with the same name (and matching storage key / origin
partitioning) participate in one bus. Names are app-chosen conventions
(e.g. "auth", "theme").
- Same origin
-
Scheme + host + port match. BroadcastChannel does not cross origins.
A tab on
app.example.com cannot talk to
cdn.example.com via the same channel name.
- Browsing context
-
A unit that has a window and a document — tabs, windows, iframes.
BroadcastChannel also works in workers (dedicated/shared/service where
supported) on that origin, not only in page scripts.
- Pub/sub (notify)
-
Publish a message; every other open listener on that channel receives
a copy. No built-in request/response, no leader, no shared heap.
Mental model: “tell other tabs X happened.”
- Shared process
-
One long-lived JS realm that many tabs attach to (classic:
SharedWorker). Can own one
WebSocket, hold derived in-memory state, or coordinate work. Heavier
than BroadcastChannel.
- SharedWorker
-
Multi-context worker with explicit ports. The HTML Standard points to
shared workers for elaborate multi-tab needs (locking, single socket,
resource sync). Use when notify is not enough.
- Structured clone
-
The algorithm that copies message data between contexts. Plain objects,
arrays, many built-ins clone; functions and DOM nodes do not.
BroadcastChannel uses serialize/deserialize only — there is
no transfer list like
Worker.postMessage.
- Sender excluded
-
The channel object that calls
postMessage does
not receive its own message. Other channels with the same
name do. If the posting tab needs the same UI update, run local logic
(or post and also handle locally).
- Storage-event bus (legacy)
-
Using
localStorage.setItem so other tabs hear a
storage event. Works as a crude notify, but couples
messaging to storage side effects, string payloads, and “other document
only” event rules. Prefer BroadcastChannel for intentional pub/sub.
- sessionStorage
-
Tab-scoped string map for a page session. Not a multi-tab bus: other
tabs do not share it. Contrast: BroadcastChannel is for cross-tab
messages, not for storing tab-private drafts.
- Service worker clients
-
A service worker can message controlled pages via
Clients / postMessage. That is a
network/control plane tool (offline, push, claim), not the default for
“tab A told tab B the theme changed.”
- Source of truth
-
Where durable authority lives — usually the server (or a real client
store like IndexedDB). A BroadcastChannel message is a
signal that something changed; it is not the store of record.