Favorites

HTML onrejectionhandled Event Attribute

☕
Enjoying this site?

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

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

Description

The onrejectionhandled event attribute is used on the <body> element (or as window.onrejectionhandled) and runs a script when a rejected Promise that was reported as unhandled gets a handler later.

It always follows an onunhandledrejection event for the same promise. Error-tracking code can use it to remove the earlier report, since the rejection was dealt with after all. The event is a PromiseRejectionEvent with the properties promise and reason.

Syntax

<body onrejectionhandled="script">

Values

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

Example

<!DOCTYPE html>
<html>
<head>
<title>onrejectionhandled event</title>
</head>
<body>
<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 onrejectionhandled 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