Name
MessageEvent — a message from another execution context
Inherits from
Event
Synopsis
Various APIs use message events for asynchronous communication between
unrelated execution contexts. The Window,
Worker, WebSocket,
EventSource, and MessagePort objects all define onmessage properties for handling message
events. The message associated with a message event is any
JavaScript value that can be cloned as described in Structured Clones. The message is wrapped in a
MessageEvent object and available on the data property. The various APIs that rely
on message events also define a few additional properties in the
MessageEvent object. Message events do not bubble and have no
default action to cancel.
Properties
readonly anydataThis property holds the message that is being delivered.
datacan be of any type that can be cloned with the structured clone algorithm (Structured Clones): this includes core JavaScript values including objects and arrays but not functions. Client-side values such as Document and Element nodes are not allowed, although Blobs and ArrayBuffers are.readonly stringlastEventIdFor message events on an EventSource (Comet with Server-Sent Events), this field contains the
lastEventIdstring, if any, that was sent by the server.readonly stringoriginFor message events on an EventSource (Comet with Server-Sent Events) or on a Window (Cross-Origin Messaging), this property contains the origin URL of the message sender.
readonly MessagePort[]portsFor message events on a Window ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access