postMessage method

void postMessage(
  1. JSAny? message, [
  2. JSObject optionsOrTransfer
])

The postMessage() method of the Worker interface sends a message to the worker. The first parameter is the data to send to the worker. The data may be any JavaScript object that can be handled by the structured clone algorithm.

The Worker postMessage() method delegates to the MessagePort MessagePort.postMessage method, which adds a task on the event loop corresponding to the receiving MessagePort.

The Worker can send back information to the thread that spawned it using the DedicatedWorkerGlobalScope.postMessage method.

Implementation

external void postMessage(
  JSAny? message, [
  JSObject optionsOrTransfer,
]);