CKTIS / JavaScript
unhandledrejection — unhandled promise rejection
The unhandledrejection event reports a Promise rejection that remains unhandled when the browser reports it. It exposes the promise and rejection reason and is useful for diagnostics, not as a replacement for local error handling.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
window.addEventListener("unhandledrejection", (event) => { /* event.promise, event.reason */ });unhandledrejection is a Web platform event dispatched to a global object, such as window, as a PromiseRejectionEvent. It is not ECMAScript syntax. event.promise identifies the rejected promise, and event.reason contains its rejection reason — any value, not necessarily an Error object.
Notification is asynchronous: the browser accounts for handlers added during microtask processing and checks handling status again before dispatch. Consequently, Promise.reject() alone does not guarantee an event. Attaching .catch() early enough can prevent it; attaching a handler after reporting can cause a separate rejectionhandled event.
The event is cancelable. event.preventDefault() suppresses default console reporting for that rejection, but does not change the promise's state or replace .catch() or try/catch around await. Use it deliberately to avoid hiding defects. This mechanism is not a complete error log: tracking is skipped for scripts with the muted errors flag, including some cross-origin script cases.
The example filters events by promise identity, logs the reason, and removes its listener. Run it as a script in an empty browser page, not in Node.js. This API is specified by the HTML Living Standard; an ECMAScript edition or the presence of Node 24 does not establish browser support.
Examples
(() => {
let rejected;
function report(event) {
if (event.promise !== rejected) return;
event.preventDefault();
window.removeEventListener("unhandledrejection", report);
console.log("unhandled:", event.reason);
}
window.addEventListener("unhandledrejection", report);
rejected = Promise.reject("demo");
})();Result
unhandled: demo
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.