MessageChannel
Last updated Apr 23, 2026
Background
The MessageChannel API ↗︎ provides a way to create a communication channel between different parts of your application.
The Workers runtime provides a minimal implementation of the MessageChannel API that is currently limited to uses with a single Worker instance. This means that you can use MessageChannel to send messages between different parts of your Worker, but not across different Workers.
const { port1, port2 } = new MessageChannel();
port2.onmessage = (event) => {
console.log('Received message:', event.data);
};
port2.postMessage('Hello from port2!');
Any value that can be used with the structuredClone(...) API can be sent over the port.
Differences
There are a number of key limitations to the MessageChannel API in Workers:
- Transfer lists are currently not supported. This means that you will not be able to transfer ownership of objects like
ArrayBufferorMessagePortbetween ports. - The
MessagePortis not yet serializable. This means that you cannot send aMessagePortobject through thepostMessagemethod or via JSRPC calls. - The
'messageerror'event is only partially supported. If the'onmessage'handler throws an error, the'messageerror'event will be triggered, however, it will not be triggered when there are errors serializing or deserializing the message data. Instead, the error will be thrown when thepostMessagemethod is called on the sending port. - The
'close'event will be emitted on both ports when one of the ports is closed, however it will not be emitted when the Worker is terminated or when one of the ports is garbage collected.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers/runtime-apis/messagechannel/#page","headline":"MessageChannel","description":"Channel messaging with MessageChannel and MessagePort","url":"https://developers.cloudflare.com/workers/runtime-apis/messagechannel/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/runtime-apis/messagechannel/og.png?v=fc9ad57d9cc5f17b","dateModified":"2026-04-23","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Node.js APIs available in Cloudflare Workers title: Node.js compatibility image: https://developers.cloudflare.com/workers/runtime-apis/nodejs/og.png?v=a1501321a77372ed
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.
Docs