Web Browsers and Unhandled Rejections
Look at how web browsers track and detect unhandled rejections.
Unhandled rejection tracking for web browsers
Unhandled rejection tracking for web browsers is defined in the HTML specification. At the core of unhandled rejection tracking are two events that are emitted by the globalThis
object:
unhandledrejection
: This is emitted when a promise is rejected and no rejection handler is called within one turn of the event loop.rejectionhandled
: This is emitted when a promise is rejected and a rejection handler is called after one turn of the event loop.
These two events are designed to be used together to accurately detect unhandled promise rejections. Here’s an example showing when each event is triggered:
Get hands-on with 1400+ tech skills courses.