Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available in Web Workers.
The messageerror event is fired on a MessagePort object when it receives a message that can't be deserialized.
This event is not cancellable and does not bubble.
Use the event name in methods like addEventListener(), or set an event handler property.
addEventListener("messageerror", (event) => { })
onmessageerror = (event) => { }
A MessageEvent. Inherits from Event.
This interface also inherits properties from its parent, Event.
MessageEvent.data Read only
The data sent by the message emitter.
MessageEvent.origin Read only
A string representing the origin of the message emitter.
MessageEvent.lastEventId Read only
A string representing a unique ID for the event.
MessageEvent.source Read only
A MessageEventSource (which can be a WindowProxy, MessagePort, or ServiceWorker object) representing the message emitter.
MessageEvent.ports Read only
An array containing all MessagePort objects sent with the message, in order.
A common cause of messageerror events is attempting to send a SharedArrayBuffer object, or a buffer view backed by one, across agent clusters. For example, a window is not in the same agent cluster as a shared worker it created, so suppose the page runs the following code:
const worker = new SharedWorker("worker.js");
worker.port.start();
worker.port.addEventListener("message", (event) => {
worker.port.postMessage(new SharedArrayBuffer(1024));
});
And worker.js contains the following code:
self.addEventListener("connect", (event) => {
console.log("Hello");
const port = event.ports[0];
port.start();
port.postMessage("Port connected");
port.addEventListener("messageerror", (event) => {
console.log("Message error");
});
});
Then the shared worker will receive a messageerror event when it tries to deserialize the message sent from the window.
Note: You can use browser devtools to debug your SharedWorker, by entering a URL in your browser address bar to access the devtools workers inspector; for example, in Chrome, the URL chrome://inspect/#workers, and in Firefox, the URL about:debugging#workers.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
messageerror_event |
60 | 18 | 57 | 47 | 16.4 | 60 | 57 | 47 | 16.4 | 8.0 | 60 | 16.4 |
message.
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MessagePort/messageerror_event