Events
onmessageerror
An incoming message cannot be deserialized in the receiving context. Window event handler, exposed through the body element in HTML; register on window rather than on an arbitrary element. Event interface: MessageEvent. For the described native event: bubbles: no; cancelable: no. Handle failure separately from message; ordinary text sent with postMessage does not trigger this error. Example: Run this as a standalone page; the browser must generate the relevant lifecycle event. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.
Formal Syntax & Structure
html syntaxhtml
<body onmessageerror="handleEvent(event)"> window.addEventListener("messageerror", event => { /* handle event */ });Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| onmessageerror | JavaScript handler body | Optional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute. |
| event | MessageEvent | Event object delivered to the addEventListener callback; event.type is "messageerror". Inspect target, currentTarget, bubbles and cancelable as appropriate. |
Working Example
Example Snippethtml
<p>Window event monitor</p><p role="status" id="log">Waiting for messageerror</p><script> const target = window; const log = document.getElementById("log"); target.addEventListener("messageerror", event => { log.textContent = String(event.type); });</script>