Favorites

HTML onunhandledrejection Event Attribute

☕
Enjoying this site?

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

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

Description

The onunhandledrejection event attribute is used on the <body> element (or as window.onunhandledrejection) and runs a script when a JavaScript Promise is rejected and no handler deals with the rejection, such as a missing .catch() or a try...catch around await.

The event is a PromiseRejectionEvent with the properties promise and reason (usually an Error). It is the Promise equivalent of window.onerror and is often used to send errors to a logging service. Calling event.preventDefault() stops the browser from printing the error to the console.

If a handler is attached to the promise later, the onrejectionhandled event fires.

Syntax

<body onunhandledrejection="script">

Values

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

Example

<!DOCTYPE html>
<html>
<head>
<title>onunhandledrejection event</title>
</head>
<body>
<button onclick="rejectNow()">Reject a promise</button>
<button onclick="rejectLater()">Reject and handle later</button>
<ul id="log"></ul>
<script>
function log(text) {
var li = document.createElement("li");
li.textContent = text;
document.getElementById("log").appendChild(li);
}
function rejectNow() {
Promise.reject(new Error("Nobody handled me"));
}
function rejectLater() {
var p = Promise.reject(new Error("Handled late"));
setTimeout(function () { p.catch(function () {}); }, 500);
}
window.onunhandledrejection = function (event) {
log("unhandledrejection: " + event.reason.message);
};
window.onrejectionhandled = function (event) {
log("rejectionhandled: " + event.reason.message);
};
</script>
</body>
</html>
Open in editor

Browser Support

The following information will show you the current browser support for the HTML onunhandledrejection 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