Events

onrejectionhandled

A previously reported unhandled promise rejection later gains a rejection handler. Window event handler, exposed through the body element in HTML; register on window rather than on an arbitrary element. Event interface: PromiseRejectionEvent. For the described native event: bubbles: no; cancelable: no. Read promise and reason for diagnostics; do not use it as normal application control flow. Example: Observe an existing rejected promise from a standalone test page; this example deliberately does not create an unhandled rejection. The event listener is registered with addEventListener(), which avoids inline script handlers and supports multiple listeners. Inline handlers require a CSP that permits them; do not insert untrusted code into handler attributes.

Formal Syntax & Structure

html syntaxhtml
<body onrejectionhandled="handleEvent(event)">  window.addEventListener("rejectionhandled", event => { /* handle event */ });

Parameters & Attributes

NameTypeDescription
onrejectionhandledJavaScript handler bodyOptional HTML event-handler code; the example uses a registered listener instead. Not a Boolean attribute.
eventPromiseRejectionEventEvent object delivered to the addEventListener callback; event.type is "rejectionhandled". Inspect target, currentTarget, bubbles and cancelable as appropriate.

Working Example

Example Snippethtml
<p>Window event monitor</p><p role="status" id="log">Waiting for rejectionhandled</p><script>  const target = window;  const log = document.getElementById("log");  target.addEventListener("rejectionhandled", event => {    log.textContent = String(String(event.reason));  });</script>
HTML Reference