MessageChannel

Entangled ports

A message channel is two MessagePorts born already connected. A message posted on one is delivered only at the other.

You hold Who hears AuthZ
MessageChannel A port The entangled twin Who you gave the port to
window.postMessage A window That window’s listeners targetOrigin + event.origin
BroadcastChannel A name Every same-origin subscriber Same origin + same name
Same-context call A function Whoever you invoked Ordinary JS visibility
const { port1, port2 } = new MessageChannel();
port1.onmessage = (e) => console.log(e.data);
port2.postMessage("hello");

Spec: HTML §9.4 · ports as capabilities