CKTIS / HTML
onmessageerror — handling message deserialization failure
The onmessageerror attribute on body sets the Window object's messageerror handler. The event signals failure to deserialize an incoming message, rather than an arbitrary communication error.
Version: WHATWG HTML Living Standard; index snapshot date recorded separately
Syntax
<body onmessageerror="handler(event)">
window.onmessageerror = handler;
window.addEventListener("messageerror", handler);onmessageerror is an HTML event-handler attribute for messageerror. On body, it sets a handler for the associated Window, not for an event targeting the element itself. It is not a global attribute for arbitrary elements. Its attribute value is JavaScript code; the event parameter exposes a MessageEvent.
For communication through postMessage(), the receiver reconstructs the transmitted data using structured deserialization. If that step fails, it receives messageerror instead of message. This is not a general notification of lost messages or an error executing receiver code. A sender-side serialization failure can instead throw a synchronous DataCloneError from the postMessage() call.
In JavaScript, assign a function to window.onmessageerror or use window.addEventListener("messageerror", handler). The attribute on body and the window.onmessageerror property refer to the same handler; another assignment replaces it, and assigning null removes it. addEventListener() allows independent listeners.
The example deliberately dispatches a synthetic event to window for a deterministic result. It checks the attribute's event-handler wiring, but does not cause an actual deserialization failure. A security policy blocking inline scripts or inline event handlers can prevent it from running.
Examples
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>onmessageerror demo</title>
<body onmessageerror="document.getElementById('result').textContent = event.type">
<pre id="result">waiting</pre>
<script>
window.dispatchEvent(new MessageEvent('messageerror'));
</script>
</body>
</html>Result
messageerror
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.