Recommended Free Tools
window.onerror does not capture unhandled Promise rejections. It handles script errors; a rejection with no handler is reported through the separate unhandledrejection event. Add a listener for that event to log or report escaped rejections.
Why doesn’t window.onerror catch a rejected Promise?
Browsers use separate reporting paths for script errors and Promise rejections. The Window error event reports synchronous script errors. When a Promise is rejected without a rejection handler, the browser fires unhandledrejection on the relevant global scope, usually window. MDN describes the distinction in its Window: error event documentation.
As an Amazon Associate I earn from qualifying purchases.
How do you capture unhandled rejections?
Register a listener on the 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.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Scan for outdated or missing drivers - takes under a minute3Repair Windows errors before they cause bigger problemsYou can also assign window.onunhandledrejection. Use addEventListener when listeners need to coexist: assigning the property replaces any existing property handler.
#1 Best Overall
What does the global listener cover—and what does it not?
The event reports Promise rejections that have no rejection handler when the browser reports them. It is a diagnostic safety net, not a guarantee that every failure will reach your code. In particular, cross-origin script rejections may not dispatch unhandledrejection, because exposing rejection details could reveal data across origins. See MDN’s Window: unhandledrejection event documentation.
Handle expected failures near the operation that can fail. For example, use try/catch around an await when you can recover, or attach .catch() to a Promise chain. The global listener can then help reveal rejections that escaped those local handling paths.
Rank #2
Should you call preventDefault()?
unhandledrejection is cancelable. Calling event.preventDefault() suppresses the browser’s default handling, such as reporting the rejection in the console. Do so only if your application deliberately takes responsibility for handling or reporting the failure; otherwise, leave the default behavior intact while logging or observing the event.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →What if the rejection gets handled later?
A Promise can be reported as unhandled and then receive a rejection handler afterward. The global scope may then fire rejectionhandled. Instrumentation can use this signal to update an earlier report rather than treating the first event as proof that the rejection remained unhandled indefinitely. MDN documents this event in its Window: rejectionhandled event reference.
Browser event names differ from Node.js
In browser code, listen for unhandledrejection on the global scope. Node.js uses a differently capitalized process event, unhandledRejection; its process-listener examples are not browser Window event handlers.
Quick Recap
Best Value
Rank #4
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.




