Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

messageerror — worker message deserialization failure

The messageerror event on a Worker signals that an incoming message could not be deserialized. Distinguish it from a sending failure in postMessage() and from the error event associated with a worker error.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

worker.addEventListener("messageerror", (event) => { /* handle receive failure */ });
worker.onmessageerror = (event) => { /* handle receive failure */ };

The messageerror event fires on a Worker object when an incoming message from the worker cannot be deserialized: its value cannot be reconstructed on the receiving side. It belongs to Web APIs, rather than a particular ECMAScript edition. The event is a MessageEvent; it does not bubble and cannot be canceled.

Register a handler with worker.addEventListener("messageerror", handler) or assign a function to worker.onmessageerror. The first form allows multiple listeners; the second sets a single handler property. Direction matters: a listener on Worker handles reception in the code that created the worker; inside a dedicated worker, use self.addEventListener("messageerror", handler) to handle reception from its creator.

Do not confuse this event with every communication problem. Attempting to send a value that cannot be cloned can throw a synchronous DataCloneError from postMessage() — handle that with try...catch at the sender. The error event concerns a worker error, not specifically message deserialization. Nor is messageerror application-data validation; a successfully received message still needs validation.

The example deliberately dispatches a synthetic MessageEvent on a plain EventTarget, deterministically demonstrating listener invocation and event flags without worker files. It does not cause a real deserialization failure or establish native event support on Worker. MDN marks the Worker variant as having limited availability: check compatibility for your target browsers. Having Node 24 in a repository does not prove browser support for this API.

Examples

(() => {
  const target = new EventTarget();
  target.addEventListener("messageerror", (event) => {
    console.log(`${event.type}: bubbles=${event.bubbles}, cancelable=${event.cancelable}`);
  });
  target.dispatchEvent(new MessageEvent("messageerror"));
})();

Result

messageerror: bubbles=false, cancelable=false

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources