Further reading on message ports
This site builds on a lot of other people's work. Here are 185 places to read more about MessageChannel, MessagePort, postMessage, transferable objects and SharedWorker: the reference pages, the specifications, articles, libraries, talks and research papers. Each link has one line on what it covers.
Not much has been written about message ports on their own. Most of the writing and nearly all of the research is about window.postMessage and workers, so those are here too.
The links were last checked on 2026-11-21. If one is broken, or something good is missing, please open an issue.
Reference pages
The MDN reference for each API this site uses. Each page has examples and a browser support table.
- Channel Messaging API MDN Overview of MessageChannel and MessagePort.
- Using channel messaging MDN A worked example that passes a port to an iframe and replies over it.
- MessageChannel MDN The constructor that makes two connected ports.
- MessagePort MDN postMessage(), start(), close() and the message and messageerror events.
- MessagePort: start() MDN Why a port with addEventListener receives nothing until start() is called.
- MessageEvent MDN The event every message arrives as, with data, origin, source and ports.
- Window: postMessage() MDN Sending to another window or frame, with the target origin and the security notes.
- Worker: postMessage() MDN Sending to a dedicated worker.
- ServiceWorker: postMessage() MDN Sending from a page to a service worker.
- Client: postMessage() MDN Sending from a service worker to a page.
- Transferable objects MDN The list of things that can be moved instead of copied, and what happens to the sender's copy.
- The structured clone algorithm MDN What can be copied in a message and what cannot.
- Window: structuredClone() MDN The same copy and transfer rules without sending a message.
- SharedWorker MDN One worker shared by every same-origin page, reached through a port.
- SharedWorkerGlobalScope: connect event MDN How a shared worker receives the port for each page that connects.
- Broadcast Channel API MDN Sending to every same-origin context by name. It cannot carry transferables.
- Using web workers MDN The guide to dedicated and shared workers.
- ReadableStream MDN A stream can be transferred. Its support table has a row for that.
- HTMLCanvasElement: transferControlToOffscreen() MDN Handing a canvas to a worker as a transferable OffscreenCanvas.
- Web Locks API MDN A lock that is released when its holder goes away, which is one way to learn that the other end of a port has gone.
- State Partitioning MDN Firefox's partitioning by top-level site. Shared workers and BroadcastChannel are on the list, so one inside a third-party iframe is not shared across sites.
- Document: requestStorageAccess() MDN Asking for unpartitioned storage in an embedded frame. Chrome can also grant an unpartitioned SharedWorker and BroadcastChannel.
- Can I use: Channel messaging caniuse.com Browser support for MessageChannel.
- Can I use: Shared Web Workers caniuse.com Browser support for SharedWorker.
Specifications
The standards that define the behaviour.
- HTML Standard: Web messaging WHATWG The current specification for cross-document messaging, channel messaging and BroadcastChannel.
- HTML Standard: Channel messaging WHATWG MessageChannel and MessagePort, including the rule that a port with a listener is not garbage collected.
- HTML Standard: Ports as the basis of an object-capability model on the web WHATWG A short section of the standard that describes a port as a permission that can be handed on.
- HTML Standard: Security of cross-document messaging WHATWG What the standard asks authors to check when they receive a message.
- HTML Standard: Safe passing of structured data WHATWG The definition of serializable objects, transferable objects and structured clone.
- HTML Standard: Web workers WHATWG Dedicated and shared workers, and the implicit port each dedicated worker has.
- Streams Standard: Transferable streams WHATWG How a stream is moved to another context: the two halves are joined by a message port.
- Transferable streams explainer WHATWG The reasons for making streams transferable, with examples.
- Service Workers W3C Defines postMessage between pages and service workers.
- Web Locks API W3C The specification for locks shared by tabs and workers of one origin.
- Client-Side Storage Partitioning W3C Privacy Community Group The plan for partitioning storage and communication APIs, including SharedWorker and BroadcastChannel, by top-level site.
- The Storage Access API W3C Privacy Community Group The repository for the API an embedded frame uses to ask for unpartitioned access.
- HTML5 Web Messaging (W3C Recommendation, 2015) W3C, 2015 The older W3C snapshot of the same text. It has been superseded by the HTML Standard and is useful for history.
How the standards changed
Discussions, proposals and browser announcements that show why the APIs behave as they do.
- Cross-Window Messaging John Resig, 2008 An early description of postMessage, written when Firefox 3 was about to ship it.
- Computing with JavaScript Web Workers John Resig, 2009 An early description of workers and their message passing.
- W3C bug 13584: Channel Messaging Origins W3C Bugzilla, 2011 A security review asked why messages on a port carry no origin. The reply led to the capability section in the standard.
- Re: postMessage, workers and sandboxing Brad Hill, public-webappsec, 2015 A mailing list reply that explains a port is meant to work as a capability its owner can delegate.
- Explainer: a close event for MessagePort Fergal Daly, 2023 The proposal for an event that tells one port the other end has gone.
- Intent to Prototype and Ship: MessagePort.onclose blink-dev, 2023 The Chromium discussion about shipping the close event.
- Chrome Platform Status: MessagePort close event Chrome Platform Status The current shipping status of the close event in Chrome, with links to the other browsers' positions.
- W3C TAG review 923: Adding a close event to MessagePort W3C TAG, 2023 The design review of the close event.
- Intent to Ship: Streams API: transferable streams blink-dev, 2020 The Chromium discussion about shipping transferable streams.
- WebKit Features in Safari 16.0 WebKit, 2022 The release in which SharedWorker returned to Safari, on macOS and iOS.
- Intent to Experiment: SharedWorker on Android blink-dev, 2025 The start of Chrome's trial of SharedWorker on Android, with the concern that Android may stop the worker's process.
- Intent to Ship: SharedWorker on Android blink-dev, 2026 The Chromium discussion about shipping SharedWorker in Chrome for Android.
- Intent to Ship: Extended lifetime shared workers blink-dev, 2026 A proposal to let a shared worker keep running for a short time after its last page closes.
- Storage Partitioning Google Privacy Sandbox What Chrome partitions by top-level site, including SharedWorker and BroadcastChannel.
- Changes to BFCache behavior with extension message ports Chrome for Developers, 2024 What happens to an extension's open port when its page goes into the back/forward cache.
Guides from browser teams
- Transferable objects - Lightning fast Eric Bidelman, Chrome for Developers, 2011 The announcement of transferable ArrayBuffers, with the first timings of transfer against copy.
- Use web workers to run JavaScript off the browser's main thread Surma, web.dev, 2019 Why to move work to a worker, and how Comlink hides the messages.
- Workers overview web.dev, 2020 How dedicated workers and service workers differ, and how a page talks to each.
- Two-way communication with service workers web.dev, 2020 Compares postMessage, a MessageChannel and BroadcastChannel for talking to a service worker.
- Broadcast updates to pages with service workers web.dev, 2020 Sending from a service worker to every open page.
- Deep-copying in JavaScript using structuredClone Surma, web.dev, 2021 What structured clone copies, what it drops, and how transfer fits in.
- An overview of web workers web.dev A short lesson on workers and their messages from the Learn Performance course.
- BroadcastChannel API - A message bus for the web Eric Bidelman, Chrome for Developers, 2016 An introduction to BroadcastChannel and how it compares with postMessage and SharedWorker.
- Message passing in Chrome extensions Chrome for Developers Extensions have their own long-lived Port object. This explains how it works and how it differs.
- How fast are web workers? Guillaume Cedric Marty, Mozilla Hacks, 2015 Measurements of worker start-up and message time on a low-end phone.
- Service Worker postMessage() sample Google Chrome samples A small running example that sends a MessageChannel port to a service worker and waits for the reply.
Performance and timing
What a message costs, and how message ports are used for scheduling.
- Is postMessage slow? Surma, 2019 Measures the cost of structured clone by payload size on several devices and gives size budgets.
- When should you be using Web Workers? Surma, 2019 The argument for workers on slow phones, and where the cost of messaging fits.
- High-performance Web Worker messages Nolan Lawson, 2016 Compares sending objects with sending JSON strings. The post has later updates as browsers changed.
- Deep-copying in JavaScript Surma, 2018 Uses a MessageChannel to reach structured clone before structuredClone() existed, and times it.
- Improving Webapp Performance with Multi-Threading: a Study of Web Workers' Communication Overhead InfoQ, 2019 A summary of Surma's measurements.
- Why do browsers throttle JavaScript timers? Nolan Lawson, 2025 Explains timer clamping and why libraries post to a MessageChannel to schedule a task without the delay.
- The State Of Web Workers In 2021 Surma, Smashing Magazine, 2021 A survey of how workers are used, the cost of postMessage and the tools around it.
Posts about ports, frames and shared workers
There are not many articles that go past the basics. These are the ones I found.
- Messing with MessageChannel David Humphrey, 2015 Uses a MessageChannel between an editor in a cross-origin iframe and the app that hosts it.
- ServiceWorker, MessageChannel, & postMessage Nicolás Bevacqua, Pony Foo, 2015 Request and reply between a page and a service worker by sending a port with each message.
- How to use async/await with postMessage Tamás Sallai, 2020 Turns a message and its reply into a promise by sending a new MessageChannel port with each request.
- Using MessageChannel to call functions within iframes Winggo Tse, Anvil, 2023 A walk-through of handing an iframe a port and calling functions over it.
- How to make postMessage type-safe in under 350 bytes Pavel Grinchenko and Travis Turner, Evil Martians, 2026 A small typed wrapper for messages between a page and an iframe over a MessageChannel.
- One-Way Sandboxed Iframes Joshua Rogers, 2025 Renders untrusted HTML in a sandboxed iframe that can be sent messages but cannot read anything back.
- The Architecture of Browser Sandboxes Alex Griss, 2025 How code playgrounds isolate code in iframes and workers, with a private port in place of the global message handler.
- Cross-window communication javascript.info A tutorial on the same-origin policy, iframes and window.postMessage.
- An Actor, a model and an architect walk onto the web... Surma, 2017 Applies the actor model to web apps, where each part only receives and sends messages.
- Reduce WebSocket Connections With Shared Workers Pusher One WebSocket held in a SharedWorker and shared by every tab.
- Scaling WebSocket Connections using Shared Workers Ayush Gupta, 2020 The same pattern, with BroadcastChannel used to reach the tabs.
- Sharing WebSocket Connections between Browser Tabs and Windows Bright Inventions, 2023 Keeps each tab's port in the shared worker and uses WeakRef to notice tabs that have closed.
- Some notes on SharedWorkers Chris How, 2024 Practical notes on debugging, lifetime and browser differences.
How products use messaging
Engineering write-ups from teams that built on postMessage, ports or shared workers.
- How to build a plugin system on the web and also sleep well at night Rudi Chen, Figma, 2019 The options Figma weighed for running third-party plugin code, from iframes with message passing to a separate JavaScript engine.
- Remote rendering: Shopify's take on extensible UI Shopify Engineering, 2021 Third-party code runs in a worker or iframe and describes its UI to the host over a MessageChannel.
- A whole new Quick Edit in Cloudflare Workers Cloudflare, 2023 Embeds VS Code for the Web in an iframe and talks to it over a transferred MessagePort.
- How we sped up Notion in the browser with WASM SQLite Carlo Francisco, Notion, 2024 A SharedWorker chooses which tab may write to the database, and Web Locks tell it when a tab has closed.
- wa-sqlite discussion 81 Roy Hashimoto The design Notion's post builds on: one tab at a time uses the database, and the other tabs send their queries to that tab.
- SQLite Wasm in the browser backed by the Origin Private File System Chrome for Developers, 2023 SQLite runs in a worker and the page talks to it with messages.
- How Partytown Works Alex Patterson, Builder.io, 2022 Third-party scripts run in a worker and reach the DOM through proxied messages.
- How Partytown's Sync Communication Works Adam Bradley, 2021 How a worker gets a synchronous answer from the main thread, using a service worker or Atomics.
- Webview API: passing messages Visual Studio Code How a VS Code extension and its webview talk with postMessage.
- MessagePorts in Electron Electron Passing ports between Electron's main process and its windows, with several worked patterns.
Libraries
Code that wraps postMessage or a MessagePort. Reading the source of the small ones is a good way to learn the API.
- Comlink Google Chrome Labs Calls across a port look like calls on a local object. This site compares it with a rebuild on the Comlink page.
- Cap'n Web Cloudflare Object-capability RPC (Remote Procedure Call) with promise pipelining. It runs over HTTP, WebSocket and MessagePort.
- Penpal Aaron Hardy Promise-based calls between a page and iframes, workers and windows.
- post-robot Daniel Brain Request and response between windows on different domains, with functions passed as arguments.
- zoid Daniel Brain Cross-domain components built on post-robot: an iframe or popup that takes props and callbacks.
- Postmate Dollar Shave Club A small promise-based library for a parent page and one iframe.
- rimless au-re A promise-based wrapper for iframes and workers.
- kkrpc Huakun Shen Typed two-way RPC over workers, iframes and other transports.
- Comctx molvqingtai RPC across contexts with a transport adapter you supply.
- async-call-rpc Jack Works JSON-RPC over any channel that can carry a message.
- workerize Jason Miller Moves a module into a worker and turns its exports into async functions.
- greenlet Jason Miller Moves one async function into its own worker.
- threads.js Andy Wermke One API for web workers and Node worker threads, with pools and observables.
- workerpool Jos de Jong A pool of workers for Node and the browser.
- coincident Andrea Giammarchi A proxy that lets a worker call the main thread and wait for the answer, using Atomics.
- Partytown QwikDev Runs third-party scripts in a web worker.
- WorkerDOM AMP Project A DOM implementation that runs in a worker and sends its changes to the page as messages.
- Remote DOM Shopify Mirrors a tree of elements from a sandboxed worker or iframe into the host page.
- broadcast-channel Daniel Meyer A BroadcastChannel that also works in older browsers and in Node.
- post-message-stream MetaMask A duplex Node-style stream over window.postMessage, used between an extension and a page.
- Endo and CapTP Endo Hardened JavaScript and a capability transfer protocol for calling objects in another context or on another machine.
- MCP-B transports WebMCP-org Model Context Protocol transports for the browser, over postMessage between tabs, iframes and extensions.
Outside the browser
The same API in server runtimes.
- Worker threads: MessageChannel and MessagePort Node.js Node's implementation, with the differences from the browser's.
- Messaging Deno MessageChannel, MessagePort and BroadcastChannel in Deno.
- MessageChannel Cloudflare Workers What MessageChannel does inside a Worker, and what it cannot do there.
- Workers Bun Workers and their messages in Bun.
Capabilities and RPC
A port gives its holder the ability to send to one place, and it can be handed on. That is the idea behind object-capability security, which has a long literature.
- Robust Composition: Towards a Unified Approach to Access Control and Concurrency Control Mark S. Miller, 2006 The thesis that sets out object capabilities and promise pipelining. Cap'n Proto, Cap'n Web and CapTP (Capability Transport Protocol) build on it.
- Cap'n Proto: RPC Protocol Kenton Varda A capability-based RPC protocol in which a reference to a remote object can be passed in a call.
- Cap'n Web: a new RPC system for browsers and web servers Kenton Varda and Steve Faulkner, Cloudflare, 2025 The same model in plain JavaScript and JSON: pass functions and objects by reference, in both directions.
- OCapN OCapN pre-standardization group Work on a shared protocol for object capabilities across a network.
- Endo Endo Documentation for Hardened JavaScript, compartments and the eventual-send API.
Security guides and write-ups
Almost all of these are about window.postMessage listeners that do not check who sent the message. A private MessagePort avoids that class of bug, because only the holder of the other end can send to it.
- HTML5 Security Cheat Sheet: Web Messaging OWASP A short checklist for sending and receiving messages.
- Controlling the web message source PortSwigger Web Security Academy How a message handler becomes a route to DOM-based attacks, with labs to practise on.
- postMessaged and Compromised Microsoft Security Response Center, 2025 Case studies of token theft and script injection through weak origin checks in Microsoft services.
- The pitfalls of postMessage Mathias Karlsson, Detectify Labs, 2016 Common mistakes in origin checks, with examples.
- postMessage Broadcasts XS-Leaks Wiki How a message sent to any origin, or the fact that one was sent at all, leaks information to another site.
Research papers: security of messaging
I found no paper that is only about MessageChannel. The research is about postMessage, frames and workers, and several papers cover ports as part of that.
- Protection and Communication Abstractions for Web Browsers in MashupOS Wang, Fan, Howell and Jackson, SOSP, 2007 Proposed browser abstractions for isolated content from different sites to talk to each other, shortly before postMessage shipped.
- Securing Frame Communication in Browsers Barth, Jackson and Mitchell, USENIX Security, 2008 Found a confidentiality flaw in the first postMessage design. The fix is the target origin argument used today.
- Attacks on JavaScript Mashup Communication Barth, Jackson and Li, W2SP, 2009 Shows how libraries layered on postMessage and similar channels let one side compromise the other. PDF.
- The Emperor's New APIs: On the (In)Secure Usage of New Client-side Primitives Hanna, Shin, Akhawe, Boehm, Saxena and Song, W2SP, 2010 Studies postMessage protocols in Facebook Connect and Google Friend Connect and finds missing origin checks.
- Privilege Separation in HTML5 Applications Akhawe, Saxena and Song, USENIX Security, 2012 Splits an application into unprivileged parts that can only reach a small privileged parent by postMessage.
- Treehouse: JavaScript Sandboxes to Help Web Developers Help Themselves Ingram and Walfish, USENIX ATC, 2012 Runs untrusted scripts in web workers with a virtual DOM, with every request checked as it crosses by message.
- The Postman Always Rings Twice: Attacking and Defending postMessage in HTML5 Websites Son and Shmatikov, NDSS, 2013 A study of message receivers on the Alexa top 10,000 sites. Many checked the origin incorrectly or not at all.
- Protecting Users by Confining JavaScript with COWL Stefan, Yang, Marchenko, Russo, Herman, Karp and Mazières, OSDI, 2014 Adds labels to browser contexts and to the messages they exchange, so a page can share data with code it does not trust.
- ZigZag: Automatically Hardening Web Applications Against Client-side Validation Vulnerabilities Weissbacher, Robertson, Kirda, Kruegel and Vigna, USENIX Security, 2015 Learns what normal messages look like and blocks ones that do not fit, to protect weak postMessage receivers.
- How the Web Tangled Itself: Uncovering the History of Client-Side Web (In)Security Stock, Johns, Steffens and Backes, USENIX Security, 2017 Twenty years of archived pages, including how postMessage use and missing origin checks grew over time.
- Study and Mitigation of Origin Stripping Vulnerabilities in Hybrid-postMessage Enabled Mobile Applications Yang, Huang, Gu and Mendoza, IEEE S&P, 2018 postMessage between native code and a WebView loses the origin of the sender. This is the project page.
- Site Isolation: Process Separation for Web Sites within the Browser Reis, Moshchuk and Oskov, USENIX Security, 2019 How Chrome puts each site in its own process. Explains what it took to keep postMessage working between frames in different processes.
- PMForce: Systematically Analyzing postMessage Handlers at Scale Steffens and Stock, ACM CCS, 2020 Automated analysis of message handlers on the top 100,000 sites. It found 111 handlers it could exploit automatically.
- Careful Who You Trust: Studying the Pitfalls of Cross-Origin Communication Meiser, Laperdrix and Stock, ACM AsiaCCS, 2021 Maps which sites trust which others through postMessage and CORS (Cross-Origin Resource Sharing), and how far a flaw in one site reaches.
Research papers: timing, workers and concurrency
- Fantastic Timers and Where to Find Them: High-Resolution Microarchitectural Attacks in JavaScript Schwarz, Maurice, Gruss and Mangard, Financial Cryptography, 2017 Builds precise timers from other browser features after performance.now() was made coarse. Message passing between contexts is one of the building blocks.
- Loophole: Timing Attacks on Shared Event Loops in Chrome Vila and Köpf, USENIX Security, 2017 A page posts messages to itself and times their arrival to learn what other pages on the same event loop are doing.
- Browsix: Bridging the Gap Between Unix and the Browser Powers, Vilk and Berger, ASPLOS, 2017 Unix processes as web workers, with system calls sent to a kernel on the main thread as messages.
- Simpler Coordination of JavaScript Web Workers Krauweel and Jongmans, COORDINATION, 2017 Treats workers and postMessage as an actor language and proposes higher-level ways to coordinate them. PDF.
- Parallel and Distributed Web Programming with Actors Myter, Scholliers and De Meuter, 2018 Spiders.js, an actor framework that uses one model for web workers and for remote machines. PDF.
Talks and videos
- Is postMessage slow? - HTTP 203 Jake Archibald and Surma, Chrome for Developers, 2019 The measurements from Surma's article, talked through.
- The main thread is overworked & underpaid Surma, Chrome Dev Summit, 2019 The case for moving application logic to workers and talking to it with messages.
- A Quest to Guarantee Responsiveness: Scheduling On and Off the Main Thread Shubhie Panicker and Jason Miller, Chrome Dev Summit, 2018 Scheduling work on the main thread and moving work to workers.
- Harnessing the Power of MessageChannel and BroadcastChannel Daniel Jakobsen, GitNation, 2023 A short talk that moves an iframe example from window.postMessage to a port.
Web Intents, WebMCP and agents
The ideas the experiments on this site come from: one site asking another to do something for the person, and now an agent doing the asking.
- Web Intents (W3C Working Group Note) Greg Billock, James Hawkins and Paul Kinlan, W3C, 2013 The last published draft. An intent could carry MessagePorts and other transferables to the service that handled it.
- Connecting Web Apps with Web Intents James Hawkins, Chromium Blog, 2011 The announcement of the Web Intents work in Chrome.
- Web Intents Note Published W3C, 2013 The notice that work on the specification had stopped.
- WebIntents wiki W3C Use cases and notes from the task force.
- public-web-intents mailing list archive W3C The design discussion, including how a MessageChannel should be set up between client and service.
- WebAPI/WebActivities Mozilla Mozilla's version of the same idea, built for Firefox OS.
- Web Actions IndieWeb The IndieWeb community's notes on actions across sites, with a history of earlier attempts.
- Receiving shared data with the Web Share Target API Chrome for Developers A later API that covers one Web Intents use case: an installed web app registers to receive shares.
- WebMCP W3C Web Machine Learning Community Group The draft specification for a page to offer tools to an agent.
- WebMCP in Chrome Chrome for Developers Chrome's documentation for trying WebMCP.
- MCP Apps Model Context Protocol An MCP extension in which a tool's UI runs in an iframe and speaks JSON-RPC to its host over postMessage.
- MCP Apps SDK Model Context Protocol The specification and SDK, including the PostMessageTransport class.
- Agent Client Protocol Agent Client Protocol The protocol between an editor or other client and a coding agent, which the hub on this site carries to a web page.
My writing
I have written about these ideas since 2011.
- WebMessaging is broken paul.kinlan.me, 2011 The differences between browsers' postMessage implementations at the time.
- Web Intents: A fresh look paul.kinlan.me, 2011 The design of Web Intents as it stood in mid 2011.
- What happened to Web Intents? paul.kinlan.me, 2015 Why the project ended.
- What were the UX issues with Web Intents? paul.kinlan.me, 2016 The problems with the picker and with discovery.
- Service discovery and app interactions on the web paul.kinlan.me, 2016 How one site could find another that offers a service.
- Every browser should support a style of 'intent:' URL syntax paul.kinlan.me, 2016 A proposal for links that name an action and not a site.
- The Headless Web paul.kinlan.me, 2016 The web used through services and programs, without a page in front of the person.
- Web sites as unintended silos paul.kinlan.me, 2017 Why it is hard to move data in and out of a site in the browser.
- Reinventing Web Intents paul.kinlan.me, 2017 A middle site that hands a client a MessagePort to a service, using Comlink. The hub on this site follows from it.
- The Web is my API paul.kinlan.me, 2017 A site exposing its functions to other sites through a hidden frame and Comlink.
- Barcode detection in a Web Worker using Comlink paul.kinlan.me, 2018 A small example of moving work to a worker.
- Running FFMPEG with WASM in a Web Worker paul.kinlan.me, 2018 A large WebAssembly program in a worker, driven by messages.
- The web that never was paul.kinlan.me, 2022 Web platform projects that did not ship, Web Intents among them.
- Posts tagged postMessage paul.kinlan.me Every post with the tag.
- Posts tagged intents paul.kinlan.me Every post with the tag.
- Calling APIs from the browser shouldn't mean exposing keys aifoc.us, 2025 The problem the AI router on this site is an answer to.
- WebMCP is the new Web Intents ... maybe aifoc.us, 2026 WebMCP as a way for sites to declare what they can do.
- I think I've got it: WebMCP is the new Web Intents aifoc.us, 2026 A registry of tools that the person holds.
- Extensible web apps aifoc.us, 2026 A plugin system built on SharedWorker and MessageChannel.
- WebIntents on GitHub Paul Kinlan The original JavaScript shim and examples.