The message event of the Worker interface fires when the parent receives a message from its worker (the worker called self.postMessage(...)). Learn onmessage vs addEventListener("message"), MessageEvent.data, and how it differs from error—with five examples and try-it labs.
01
Kind
Instance event
02
Name
message
03
Type
MessageEvent
04
Handler
onmessage
05
Payload
event.data
06
Status
Baseline widely
Fundamentals
Introduction
A dedicated worker cannot update the DOM directly. It talks to the main page by posting messages. When the worker sends data with self.postMessage(...), the main thread’s Worker object fires a message event.
That is the happy path for background work: you send a job with postMessage() on the Worker, and you receive the answer on message via event.data.
💡
Beginner tip
Success uses the message event (event.data). Failures use the error event. Listen for both when you depend on a worker.
Concept
Understanding the Worker message Event
An instance event on Worker that fires when the worker’s parent receives a message from that worker.
The Worker message event is marked Baseline Widely available on MDN (since July 2015). Logos use the shared browser-image-sprite.png sprite from this project. It is available in Web Workers except Service Workers.
✓ Baseline · Widely available
Worker message event
Fires when the parent receives a message from its worker. Listen with onmessage or addEventListener("message").
UniversalWidely available
Google ChromeFull support · Desktop & Mobile
Full support
Mozilla FirefoxFull support · Desktop & Mobile
Full support
Apple SafariFull support · macOS & iOS
Full support
Microsoft EdgeFull support · Chromium
Full support
OperaFull support · Modern versions
Full support
Internet ExplorerSupported with workers in IE10+ (prefer modern browsers)
Legacy
Worker messageExcellent
Bottom line: Always attach a message handler when you expect replies—and pair it with an error handler for failures.
Wrap Up
Conclusion
The Worker message event is how the main thread receives successful replies from a dedicated worker. Read event.data, update the UI, and pair it with the error event for failures.
Attach onmessage / listeners before expecting replies
Read results from event.data
Use a typed envelope for multi-step protocols
Also listen for error in production
Clean up with terminate() when the feature is done
❌ Don’t
Confuse event.data with error’s event.message
Assume the worker can touch the DOM
Overwrite onmessage accidentally in shared helpers
Ignore structured-clone limits (functions, DOM nodes, etc.)
Leave the UI waiting with no timeout or error handler
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Worker message
Main-thread signal that the worker replied.
5
Core concepts
💬01
Fires
on worker reply
API
📌02
onmessage
or listener
Listen
📄03
event.data
MessageEvent
Payload
⚠️04
≠ error
separate channel
Compare
🎯05
Baseline
since Jul 2015
Status
❓ Frequently Asked Questions
It fires on the Worker object when the main thread receives a message from the worker—typically after the worker calls self.postMessage(...). Listen with worker.onmessage or worker.addEventListener("message", handler).
No. MDN marks the Worker message event as Baseline Widely available (since July 2015). It is not Deprecated, Experimental, or Non-standard. It is available in Web Workers except Service Workers.
A MessageEvent (inherits from Event). The payload you care about most is event.data—the value the worker posted.
message delivers successful postMessage data as event.data. error reports that the worker script failed. Listen for both when you depend on a worker.
No. Per MDN, this event is not cancellable and does not bubble.
On the Worker object created with new Worker(...), before or as soon as you expect replies. Inside the worker, send with self.postMessage(...).
Did you know?
Data crosses the boundary with the structured clone algorithm—not JSON.stringify. Most plain objects clone fine; functions, DOM nodes, and some exotic types do not.