Window: rejectionhandled event

翻译不完整。 请帮助我们翻译这篇文章!

当Promise被rejected且有rejection处理器时会在全局触发rejectionhandled 事件(通常是发生在window下,但是也可能发生在Worker中)。应用于调试一般应用回退。当Promise被rejected且没有rejection处理器处理时会触发unhandledrejection事件。这两个事件协同工作。

是否冒泡 No
是否可取消 No
接口 PromiseRejectionEvent
事件处理器属性 onrejectionhandled

例子

你可以使用rejectionhandled事件在控制台打印出被rejected的Promise,以及被rejected的原因:

window.addEventListener("rejectionhandled", event => {
  console.log("Promise rejected; reason: " + event.reason);
}, false);

说明

Specification Status Comment
HTML Living Standard
rejectionhandled
Living Standard Initial definition.

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
rejectionhandled eventChrome Full support 49Edge Full support ≤79Firefox Full support 69
Full support 69
Full support 68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
IE No support NoOpera Full support 36Safari Full support 11WebView Android Full support 49Chrome Android Full support 49Firefox Android Full support 68
Disabled
Full support 68
Disabled
Disabled From version 68: this feature is behind the dom.promise_rejection_events.enabled preference (needs to be set to true). To change preferences in Firefox, visit about:config.
Opera Android Full support 36Safari iOS Full support 11.3Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
User must explicitly enable this feature.
User must explicitly enable this feature.

参阅