A port moves. It does not copy. The sender’s handle is detached.
iframe.contentWindow.postMessage("init", origin, [port2]);
const port = event.ports[0]; // receiver
structuredClone(port2); // DataCloneError
postMessage(msg, origin, [port2]); // second time: DataCloneError
iframe.contentWindow.postMessage("init", origin, [port1]);
worker.postMessage("init", [port2]); // no targetOrigin; parent is off this pipe
| What happens | |
|---|---|
| Transfer list | Ownership moves. Receiver reads event.ports |
| Message data | Structured clone. A port in data without transfer throws |
| After transfer | Sender object is detached. Not a live twin |
| Window hop | Still has targetOrigin. Later port posts do not |
| Both ends moved | Parent is not on the pipe. Original posts drop |
Spec: HTML §9.4.1 · §9.3.3 · §2.7.2