Skip to content

Commit b0ff1cd

Browse files
committed
Changelog entry for MessageChannel
1 parent 7ef66c5 commit b0ff1cd

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Workers now includes an implementation of the MessageChannel API
3+
products:
4+
- workers
5+
date: 2025-08-11T01:00:00Z
6+
---
7+
8+
A minimal implementation of the [MessageChannel API](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel) is now available in Workers. This means that you can use `MessageChannel` to send messages between different parts of your Worker, but not across different Workers.
9+
10+
The `MessageChannel` and `MessagePort` APIs will be available by default at the global scope
11+
with any worker using a compatibility date of `2025-08-15` or later. It is also available
12+
using the `expose_global_message_channel` compatibility flag, or can be explicitly disabled
13+
using the `no_expose_global_message_channel` compatibility flag.
14+
15+
```js
16+
const { port1, port2 } = new MessageChannel();
17+
18+
port2.onmessage = (event) => {
19+
console.log('Received message:', event.data);
20+
};
21+
22+
port2.postMessage('Hello from port2!');
23+
```
24+
25+
Any value that can be used with the `structuredClone(...)` API can be sent over the port.
26+
27+
## Differences
28+
29+
There are a number of key limitations to the `MessageChannel` API in Workers:
30+
31+
* Transfer lists are currently not supported. This means that you will not be able to transfer
32+
ownership of objects like `ArrayBuffer` or `MessagePort` between ports.
33+
* The `MessagePort` is not yet serializable. This means that you cannot send a `MessagePort` object
34+
through the `postMessage` method or via JSRPC calls.
35+
* The `'messageerror'` event is only partially supported. If the `'onmessage'` handler throws an
36+
error, the `'messageerror'` event will be triggered, however, it will not be triggered when there
37+
are errors serializing or deserializing the message data. Instead, the error will be thrown when
38+
the `postMessage` method is called on the sending port.
39+
* The `'close'` event will be emitted on both ports when one of the ports is closed, however it
40+
will not be emitted when the Worker is terminated or when one of the ports is garbage collected.

0 commit comments

Comments
 (0)