Mint a pair when you need a private end to hand off. Reject it when another pipe already fits.
worker.postMessage(job); // implicit — do not mint
worker.postMessage(cmd, [channel.port2]); // extra pipe — mint
| Already have | Use |
|---|---|
| Same JS world / React callback | Call the function |
| A window handle | postMessage + targetOrigin |
| A name, many same-origin listeners | BroadcastChannel |
| Dedicated worker, one stream | Implicit port (queue already on) |
| Second stream, or a hand-off | MessageChannel + transfer list |
| Two iframes, parent should not hear | Mint, transfer both ends |
| Worker talks to a third context | Mint; implicit stays creator↔worker |
| SharedWorker, first stream per tab | worker.port / onconnect |
Spec: HTML §10.1.3.2 · §10.1.2.6 · §9.4.1.2 · §10.1.2.3