MessagePort

interface

interface MessagePort extends EventTarget

The MessagePort interface of the Channel Messaging API represents one of the two ports of a MessageChannel, allowing messages to be sent from one port and listening out for them arriving at the other.

variable

var MessagePort: { … }

The MessagePort interface of the Channel Messaging API represents one of the two ports of a MessageChannel, allowing messages to be sent from one port and listening out for them arriving at the other.

Constructors

constructor

new MessagePort(): never

Properties

onmessage

onmessage: ((this: MessagePort, ev: MessageEvent) => any) | null

onmessageerror

onmessageerror: ((this: MessagePort, ev: MessageEvent) => any) | null

prototype

readonly prototype: MessagePort

Methods

close

close(): void

Disconnects the port, so that it is no longer active.

postMessage

postMessage(message: any, transfer: Transferable[]): void

Posts a message through the channel. Objects listed in transfer are transferred, not just cloned, meaning that they are no longer usable on the sending side.

Throws a "DataCloneError" DOMException if transfer contains duplicate objects or port, or if message could not be cloned.

postMessage(message: any, options?: StructuredSerializeOptions): void

start

start(): void

Begins dispatching messages received on the port. This is implicitly called when assigning a value to this.onmessage.

addEventListener

addEventListener<K extends keyof MessagePortEventMap>(type: K, listener: (this: MessagePort, ev: MessagePortEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void

removeEventListener

removeEventListener<K extends keyof MessagePortEventMap>(type: K, listener: (this: MessagePort, ev: MessagePortEventMap[K]) => any, options?: boolean | EventListenerOptions): void
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void