# MessageChannel Resources

## Knowledge

- [Spec: HTML Living Standard — §9.4 Channel messaging (WHATWG)](https://html.spec.whatwg.org/multipage/web-messaging.html#channel-messaging)
  Primary source. Entangle / disentangle, `MessageChannel` constructor, `MessagePort` (`postMessage`, `start`, `close`, transfer steps), port message queue (disabled until `start` / `onmessage`). Use for: any normative claim.
- [Spec: HTML — §9.4.5 Ports and garbage collection](https://html.spec.whatwg.org/multipage/web-messaging.html#ports-and-garbage-collection)
  Close ports you hold so they can be collected; a listener on one end keeps a strong reference to the other. Use for: extra-pipe teardown — do not wait for GC.
- [Spec: HTML — §9.4.1.2 Ports as an object-capability model](https://html.spec.whatwg.org/multipage/web-messaging.html#ports-as-the-basis-of-an-object-capability-model-on-the-web)
  Non-normative but the right mental model: a port is a *capability you hand off*, not a window you address. Use for: two iframes holding the two ends so parent is not on the pipe.
- [Spec: HTML — §9.3 Cross-document messaging](https://html.spec.whatwg.org/multipage/web-messaging.html#web-messaging)
  How a port actually *moves*: `window.postMessage(..., [port])` and `event.ports`. Use for: transfer delivery only — origin checks stay on the window surface.
- [Spec: HTML — §2.7.2 Transferable objects](https://html.spec.whatwg.org/multipage/structured-data.html#transferable-objects)
  Transfer is irreversible: the sender’s object is detached and cannot be used or transferred again. Use for: neuter / second-transfer `DataCloneError`.
- [MDN: `MessageEvent.ports`](https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/ports)
  Frozen array of ports that arrived in the transfer list. Use for: `event.ports[0]` as the received end.
- [MDN: Channel Messaging API](https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API)
  Overview of the two-port pipe and which contexts can hold a port. Use for: first-pass API map.
- [MDN: Using channel messaging](https://developer.mozilla.org/en-US/docs/Web/API/Channel_Messaging_API/Using_channel_messaging)
  Worked iframe transfer pattern (keep `port1`, ship `port2`). Use for: the canonical “parent mints, iframe receives `event.ports[0]`” lab.
- [MDN: `MessageChannel`](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel)
  `port1` / `port2` constructor surface. Use for: the minting step.
- [MDN: `MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort)
  `postMessage`, `start`, `close`, `message` / `messageerror`. Use for: port lifetime and listener rules.
- [MDN: `MessagePort.start()`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/start)
  Queue stays paused until `start()`; implied by setting `onmessage`. Use for: the silent-listener gotcha.
- [MDN: `MessagePort.close()`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/close)
  Disconnects that end. Use for: teardown and “the other end stops hearing.”
- [WHATWG HTML issue #1766 — Add `onclose` to MessagePort](https://github.com/whatwg/html/issues/1766)
  Why `close()` used to be undetectable on the other end; spec now fires `close` on disentangle. Use for: deal-breaker / compat notes, not lesson 1.
- [Spec: HTML — §10.1.3.2 Communicating with a dedicated worker](https://html.spec.whatwg.org/multipage/workers.html#communicating-with-a-dedicated-worker)
  Dedicated workers use a MessagePort behind the scenes; that implicit port’s queue is enabled at creation (`Worker` has no `start()`). `Worker.postMessage(message, transfer)` has no `targetOrigin`. Use for: reject minting a pair for the creator↔worker stream.
- [Spec: HTML — §10.1.2.6 Providing libraries](https://html.spec.whatwg.org/multipage/workers.html#providing-libraries)
  Canonical “second pipe”: mint `MessageChannel`, keep `port1`, `worker.postMessage(cmd, [port2])`. Use for: when the implicit port is not enough.
- [MDN: `Worker.postMessage()`](https://developer.mozilla.org/en-US/docs/Web/API/Worker/postMessage)
  Transfer list is the second argument (or `options.transfer`). Use for: the worker hop that carries an extra port.
- [Spec: HTML — Shared workers introduction](https://html.spec.whatwg.org/multipage/workers.html#shared-workers-introduction)
  Platform-minted MessagePort per connection: `worker.port` on the page, `onconnect` / `event.ports[0]` inside. Use for: reject minting a pair for that first tab↔SharedWorker stream.

## Wisdom (Communities)

- [whatwg/html issues](https://github.com/whatwg/html/issues?q=MessagePort%20OR%20MessageChannel)
  Spec bugs and `onclose` / queue / GC debates. Use for: “is this specified or an engine quirk?”
- [MDN Web Docs chat / GitHub (mdn/content)](https://github.com/mdn/content/issues)
  Doc vs spec mismatches on `start()` and transfer. Use for: wording that confused a lesson.

## Gaps

- No third-party high-trust “when MessageChannel vs dedicated-worker implicit port vs SharedWorker `onconnect`” guide. Lessons 4 and 6 synthesise WHATWG workers + §9.4 rather than citing one.
- `MessagePort` `close` *event* support is newer than `close()`. Need a current compat check (Chromium shipped; confirm Firefox/Safari) before making `onclose` a design default.
