ExtendableMessageEvent: ExtendableMessageEvent() constructor
The ExtendableMessageEvent() constructor creates a new ExtendableMessageEvent object.
Syntax
js
new ExtendableMessageEvent(type)
new ExtendableMessageEvent(type, options)
Parameters
type-
A string with the name of the event. It is case-sensitive and browsers set it to
messageerrorormessage. optionsOptional-
An object that, in addition of the properties defined in
ExtendableEvent(), can have the following properties:dataOptional-
The event's data; this can be any data type. It defaults to
null. originOptional-
A string that defines the origin of the corresponding service worker's environment settings object. It defaults to
"". lastEventIdOptional-
A string that defines the last event ID of the event source. It defaults to
"". sourceOptional-
The
Client,ServiceWorkerorMessagePortthat sent the message. It defaults tonull. portsOptional-
An array containing the
MessagePortobjects connected to the channel sending the message. It defaults to an empty array.
Return value
A new ExtendableMessageEvent object.
Examples
js
const options = {
data: "hello message",
source: MessagePortReference,
ports: MessagePortListReference,
};
const myEME = new ExtendableMessageEvent("message", init);
Specifications
| Specification |
|---|
| Service Workers # dom-extendablemessageevent-extendablemessageevent |
Browser compatibility
BCD tables only load in the browser