Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

window.onerror does not report unhandled Promise rejections. It handles script errors; a rejected Promise without a rejection handler uses a separate browser event, unhandledrejection. Listen for that event to capture the rejection reason and the Promise that rejected.

Why window.onerror does not catch a rejected Promise

The browser has separate reporting paths for script errors and unhandled Promise rejections. The Window error event reports synchronous script errors. When a Promise rejection has no rejection handler, the browser fires unhandledrejection on the relevant global scope, usually window. MDN notes that this also covers an uncaught throw inside an async function when no rejection handler is attached. See MDN’s Window: error event documentation.

Listen for unhandledrejection

Add a listener to the page’s global object:

window.addEventListener("unhandledrejection", (event) => {
  console.error("Unhandled promise rejection:", event.reason);
});

The event is a PromiseRejectionEvent. Its reason property contains the rejection value, and promise identifies the rejected Promise. A rejection reason can be any value—not necessarily an Error—so avoid assuming it has properties such as message or stack. The same event can be handled with window.onunhandledrejection, but assigning that property replaces any handler already assigned there. addEventListener allows listeners to coexist. See MDN’s Window: unhandledrejection event documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What the global handler can—and cannot—tell you

It is a fallback for rejections without a handler

Use the global listener as a diagnostic safety net for rejected Promises that escaped local handling. It does not replace handling expected failures where they occur: use try/catch around await when recovery is possible, or .catch() for Promise chains.

Cross-origin rejections may not reach it

A rejection from a cross-origin script may not dispatch unhandledrejection, because exposing the event could reveal information. A global listener therefore cannot guarantee capture of every rejection.

A rejection may be handled later

If a rejection is reported as unhandled and code attaches a rejection handler afterward, the browser can fire rejectionhandled. Instrumentation can use this event to qualify or update an earlier report instead of treating it as proof that the rejection stayed unhandled. See MDN’s Window: rejectionhandled event documentation.

Decide whether to suppress the browser’s default report

The unhandledrejection event is cancelable. Calling event.preventDefault() suppresses default handling, such as reporting the rejection in the console. Do so only if your application has deliberately taken responsibility for handling or reporting the failure; otherwise, leave the default behavior intact.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use the browser event, not Node.js’s process event

Browser pages use the lowercase event name unhandledrejection. Node.js has a differently capitalized process event, unhandledRejection; its process-listener code is not the browser-page API. For the browser’s event details and handling options, consult MDN’s Window: unhandledrejection event documentation.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.