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 August 2016.
Note: This feature is available in Web Workers.
The MessageEvent() constructor creates a new MessageEvent object.
A string with the name of the event. It is case-sensitive and browsers always set it to message.
options OptionalAn object that, in addition of the properties defined in Event(), can have the following properties:
data OptionalThe data you want contained in the MessageEvent. This can be of any data type, and will default to null if not specified.
origin OptionalA string representing the origin of the message emitter. This defaults to an empty string ('') if not specified.
lastEventId OptionalA string representing a unique ID for the event. This defaults to an empty string ("") if not specified.
source OptionalA MessageEventSource (which can be a Window, a MessagePort, or a ServiceWorker object) representing the message emitter. This defaults to null if not set.
ports OptionalAn array of MessagePort objects containing all MessagePort objects sent with the message, in order. This defaults to an empty array ([]) if not specified.
A new MessageEvent object.
| HTML # the-messageevent-interface:dom-event-constructor |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Oct 29, 2024 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.