MDN self-hosted library · e01.org

Broadcast Channel API

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
// Connection to a broadcast channel
const bc = new BroadcastChannel("test_channel");
js
// Example of sending of a very simple message
bc.postMessage("This is a test message.");
js
// A handler that only logs the event to the console:
bc.onmessage = (event) => {
  console.log(event);
};
js
// Disconnect the channel
bc.close();