Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rejectionhandled not firing

I'm trying to use rejectionhandled but I can't get it to fire. The code below should work based on all the documnation I could find. I register a listener for rejectionhandled then reject a promise and catch it. In both chrome and firefox with the flag enabled 'testing' is logged but not 'rejected'. What am I missing?

window.addEventListener("rejectionhandled", e => console.log("rejected"), false);
new Promise((resolve, reject) => setTimeout(reject, 1000)).catch(err => console.error("testing"))
like image 326
RedHatter Avatar asked Jan 19 '26 12:01

RedHatter


1 Answers

The rejectionhandled event doesn't fire on every handled rejection, it only fires on rejections that were not handled at first (causing unhandledrejection events) but then did subsequently get a handler attached.

The events are fired from the HTML implementation of the implementation-defined HostPromiseRejectionTracker in the ECMAScript spec, whose note says

HostPromiseRejectionTracker is called in two scenarios:

  • When a promise is rejected without any handlers, it is called with its operation argument set to "reject".
  • When a handler is added to a rejected promise for the first time, it is called with its operation argument set to "handle".
like image 111
Bergi Avatar answered Jan 21 '26 04:01

Bergi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!