worker.postMessage(message) sends data from the main thread to a dedicated Worker(MDN). The payload is copied with the structured clone algorithm and arrives as event.data on the worker’s message event.
Pass the required arguments shown below. Check return values and browser support before you rely on the result.
Syntax
Call worker.postMessage. Start with this line.
JavaScript
worker.postMessage(message[, transfer])
Call
What it does
worker.postMessage(message[, transfer])
Primary signature.
worker.postMessage(...)
Call with the arguments your case needs.
Built into the browser. Call worker.postMessage(...) on a Worker — no import required.
message is required. Do not call postMessage() with zero args.
Pass null explicitly when you only need a ping / wake-up.
Worker still gets a message event with e.data === null.
Useful for signals where the payload itself does not matter.
Compatibility
Browser Support
Worker.postMessage() is Baseline Widely available (MDN: since July 2015). Available in Web Workers except Service Workers — not in Node.js, Bun, or Deno (use worker_threads there).
✓ Baseline · Widely available
Worker.postMessage()
Send structured-clone data to a dedicated worker. Optional transfer list for ArrayBuffers. Safe everyday Web Worker API.
100%Browser support
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
It sends a message from the main thread to a dedicated Worker. The data is delivered in the message event’s data field inside the worker (via structured clone).
No. MDN marks Worker.postMessage() as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is available in Web Workers except Service Workers.
Almost any value the structured clone algorithm supports: strings, numbers, booleans, arrays, plain objects, Date, Map, Set, ArrayBuffer, and more—including objects with cyclical references. Functions and DOM nodes cannot be cloned.
postMessage sends one message payload. Put several values in an array or object, for example postMessage([a, b]) or postMessage({ a, b }).
An optional list of transferable objects (like ArrayBuffer) moves ownership to the worker. After transfer, the original buffer is neutered (often byteLength === 0) on the sending side.
No. It is mandatory. If you have nothing useful to send, pass null or undefined explicitly.