Favorites

HTML onmessageerror Event Attribute

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
onmessageerror
HTML Event AttributeThis event attribute is supported by all modern browsers.
Updated 22nd November 2026

Description

The onmessageerror event attribute is used on the <body> element (or as window.onmessageerror) and runs a script when the window receives a message that cannot be deserialized, for example a SharedArrayBuffer sent to a page that is not cross-origin isolated.

It is the error counterpart of onmessage, which fires for messages sent with postMessage(). The same event exists on Worker, MessagePort and BroadcastChannel objects. In practice it fires rarely, but handling it avoids losing messages silently.

Syntax

<body onmessageerror="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html>
<html>
<head>
<title>onmessageerror event</title>
</head>
<body>
<p>Messages sent with postMessage() that cannot be read will be reported here:</p>
<ul id="log"></ul>
<script>
function log(text) {
var li = document.createElement("li");
li.textContent = text;
document.getElementById("log").appendChild(li);
}
window.onmessage = function (event) { log("message: " + event.data); };
window.onmessageerror = function (event) { log("messageerror: a message could not be deserialized"); };
window.postMessage("Hello", "*");
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onmessageerror event attribute. Hover over a browser icon to see the version that first introduced support for this HTML event attribute.

This event attribute is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee