The messageerror event of the Worker interface fires when it receives a message that cannot be deserialized. Learn onmessageerror vs addEventListener("messageerror"), how it differs from message and error, and how to feature-detect—with five examples and try-it labs.
01
Kind
Instance event
02
Name
messageerror
03
Type
MessageEvent
04
Handler
onmessageerror
05
When
Deserialize fail
06
Status
Limited availability
Fundamentals
Introduction
Most worker replies arrive through the message event with a usable event.data value. Rarely, a message reaches the main thread but cannot be deserialized. Then the Worker object fires messageerror instead of a normal message.
Think of three channels: message (success), messageerror (bad decode), and error (worker script failed). Production code that depends on workers should plan for all three when support allows.
💡
Beginner tip
Everyday data (strings, numbers, plain objects, arrays) almost always deserializes fine. Labs teach you to attach and feature-detectmessageerror—forcing a real deserialize failure is uncommon in beginner demos.
Concept
Understanding the Worker messageerror Event
An instance event on Worker that fires when a received message cannot be deserialized.
A MessageEvent. Same family as the successful message event.
Event properties (MessageEvent)
Property
Meaning
data
Data from the emitter (may be unusable after a deserialize failure)
origin
Origin of the message emitter
lastEventId
Unique ID string for the event
source
Emitter (WindowProxy, MessagePort, or ServiceWorker)
ports
Related MessagePort objects when applicable
Typical pattern (MDN idea)
JavaScript
const worker = new Worker("worker.js");
worker.addEventListener("message", (event) => {
console.log(`Received message from worker: ${event.data}`);
});
worker.addEventListener("messageerror", (event) => {
console.error("Error receiving message from worker:", event);
});
Compare
⚖️ messageerror vs Related Ideas
Idea
Meaning
message
Reply arrived and deserialized successfully
messageerror
A message could not be deserialized
error
Worker script failed (throw / load, etc.)
onmessageerror
Handler property for messageerror
addEventListener("messageerror")
Same event; can stack multiple listeners
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Handler property
worker.onmessageerror = (e) => { … }
addEventListener
worker.addEventListener("messageerror", handler)
Feature-detect
"onmessageerror" in Worker.prototype
Bubbles / cancelable
No / No
MDN status
Limited availability (not Baseline)
Snapshot
🔍 At a Glance
Four facts to remember about the Worker messageerror event.
Fires
bad decode
Cannot deserialize
Listen
onmessageerror
Or addEventListener
≠ error
different
Not a script crash
Baseline
no
Limited availability
Hands-On
Examples Gallery
Examples follow MDN Worker: messageerror event. Labs use blob workers and focus on listeners, feature detection, and contrasts—plain cloneable replies still use message.
📚 Getting Started
Attach handlers the two standard ways (MDN patterns).
Example 1 — addEventListener("messageerror") (MDN Idea)
The Worker messageerror event is marked Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project. It is available in Web Workers except Service Workers. Always feature-detect.
✓ Limited availability · Not Baseline
Worker messageerror event
Fires when a received message cannot be deserialized. Listen with onmessageerror or addEventListener("messageerror").
LimitedNot Baseline
Google ChromeCheck current engine support · feature-detect
Varies
Mozilla FirefoxSupported in modern versions (feature-detect)
Modern
Apple SafariSupported from Safari 16.4+ (feature-detect)
Modern
Microsoft EdgeCheck current Chromium support · feature-detect
Varies
OperaFollow Chromium status · feature-detect
Varies
Internet ExplorerNo practical messageerror support
Unavailable
Worker messageerrorFeature-detect
Bottom line: Attach messageerror when supported, and always keep message + error handlers for everyday success and script failures.
Wrap Up
Conclusion
The Worker messageerror event covers the rare case where a reply cannot be deserialized. Pair it with message for success and error for script failures, and feature-detect because support is Limited availability.
Prefer plain cloneable payloads for beginner protocols
Log deserialize failures to monitoring
❌ Don’t
Confuse messageerror with worker error
Assume every browser exposes the handler
Treat Limited availability like Baseline Widely
Overwrite handlers accidentally in shared helpers
Wait forever for message with no timeout or fallback
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Worker messageerror
Main-thread signal that a reply could not be deserialized.
5
Core concepts
⚠️01
Fires
on bad decode
API
📌02
onmessageerror
or listener
Listen
💬03
≠ message
decode failed
Compare
🛑04
≠ error
not script crash
Compare
🎯05
Limited
not Baseline
Status
❓ Frequently Asked Questions
It fires on the Worker object when the main thread receives a message that cannot be deserialized. Listen with worker.onmessageerror or worker.addEventListener("messageerror", handler).
No. MDN does not mark the Worker messageerror event as Deprecated, Experimental, or Non-standard. It has Limited availability (not Baseline) on MDN, so feature-detect. It is available in Web Workers except Service Workers.
message means a reply arrived and decoded successfully (read event.data). messageerror means a message arrived but could not be deserialized—so you do not get a usable payload the normal way.
error means the worker script failed (throw, load failure, and similar). messageerror is specifically about failing to deserialize an incoming message, not about the worker script crashing.
No. Per MDN, this event is not cancellable and does not bubble.
Everyday cloneable values (strings, numbers, plain objects, arrays) deserialize fine. messageerror is for rarer deserialize failures. Labs focus on attaching handlers, feature detection, and contrasting related events.
Did you know?
Related events on MDN list message beside messageerror. Successful decode uses message; failed decode uses messageerror—both are MessageEvents, but only success gives you a normal usable event.data path.