Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2015.
Note: This feature is available in Web Workers.
The MessageChannel() constructor of the MessageChannel interface returns a new MessageChannel object with two new MessagePort objects.
None (undefined).
A new MessageChannel object.
In the following code block, you can see a new channel being created using the MessageChannel() constructor. When the <iframe> has loaded, we pass port2 to the <iframe> using MessagePort.postMessage along with a message. The handleMessage handler then responds to a message being sent back from the <iframe> (using onmessage), putting it into a paragraph. The port1 is listened to, to check when the message arrives.
For a full working example, see our channel messaging basic demo on GitHub (run it live too).
| HTML # dom-messagechannel-dev |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Sep 18, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.