PromiseRejectionEvent

PromiseRejectionEvent interface represents events which are sent to the global script context when JavaScript Promise s are rejected. These events are particularly useful for telemetry and debugging purposes.

For details on promise rejection events, see 承诺拒绝事件 in Using Promises .

构造函数

PromiseRejectionEvent()
创建 PromiseRejectionEvent event, given the type of event ( unhandledrejection or rejectionhandled ) and other details.

特性

Also inherits properties from its parent Event .

PromiseRejectionEvent.promise 只读
The JavaScript Promise that was rejected.
PromiseRejectionEvent.reason 只读
A value or Object indicating why the promise was rejected, as passed to Promise.reject() .

方法

This interface has no unique methods; inherits methods from its parent Event .

Events

rejectionhandled
Fired when a JavaScript Promise is rejected, and after the rejection is handled by the promise's rejection handling code.
unhandledrejection
Fired when a JavaScript Promise is rejected but there is no rejection handler to deal with the rejection.

范例

This simple example catches unhandled promise rejections and logs them for debugging purposes.

window.onunhandledrejection = function(e) {
  console.log(e.reason);
}
					

规范

规范 状态 Comment
HTML Living Standard
The definition of 'PromiseRejectionEvent' in that specification.
实时标准 初始定义。

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
PromiseRejectionEvent Chrome 49 Edge ≤79 Firefox 69
69
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 Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
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 36 Safari iOS 11.3 Samsung Internet Android 5.0
PromiseRejectionEvent() 构造函数 Chrome 49 Edge ≤79 Firefox 69
69
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 Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
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 36 Safari iOS 11.3 Samsung Internet Android 5.0
promise Chrome 49 Edge ≤79 Firefox 69
69
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 Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
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 36 Safari iOS 11.3 Samsung Internet Android 5.0
reason Chrome 49 Edge ≤79 Firefox 69
69
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 Opera 36 Safari 11 WebView Android 49 Chrome Android 49 Firefox Android 68
Disabled
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 36 Safari iOS 11.3 Samsung Internet Android 5.0

图例

完整支持
完整支持
不支持
不支持
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅

  1. PromiseRejectionEvent
  2. 构造函数
    1. PromiseRejectionEvent()
  3. 特性
    1. promise
    2. reason
  4. 继承:
    1. Event
  5. Related pages for HTML DOM
    1. BeforeUnloadEvent
    2. DOMStringMap
    3. ErrorEvent
    4. GlobalEventHandlers
    5. HTMLAnchorElement
    6. HTMLAreaElement
    7. HTMLAudioElement
    8. HTMLBRElement
    9. HTMLBaseElement
    10. HTMLBaseFontElement
    11. HTMLBodyElement
    12. HTMLButtonElement
    13. HTMLCanvasElement
    14. HTMLContentElement
    15. HTMLDListElement
    16. HTMLDataElement
    17. HTMLDataListElement
    18. HTMLDialogElement
    19. HTMLDivElement
    20. HTMLDocument
    21. HTMLElement
    22. HTMLEmbedElement
    23. HTMLFieldSetElement
    24. HTMLFormControlsCollection
    25. HTMLFormElement
    26. HTMLFrameSetElement
    27. HTMLHRElement
    28. HTMLHeadElement
    29. HTMLHeadingElement
    30. HTMLHtmlElement
    31. HTMLIFrameElement
    32. HTMLImageElement
    33. HTMLInputElement
    34. HTMLIsIndexElement
    35. HTMLKeygenElement
    36. HTMLLIElement
    37. HTMLLabelElement
    38. HTMLLegendElement
    39. HTMLLinkElement
    40. HTMLMapElement
    41. HTMLMediaElement
    42. HTMLMetaElement
    43. HTMLMeterElement
    44. HTMLModElement
    45. HTMLOListElement
    46. HTMLObjectElement
    47. HTMLOptGroupElement
    48. HTMLOptionElement
    49. HTMLOptionsCollection
    50. HTMLOutputElement
    51. HTMLParagraphElement
    52. HTMLParamElement
    53. HTMLPictureElement
    54. HTMLPreElement
    55. HTMLProgressElement
    56. HTMLQuoteElement
    57. HTMLScriptElement
    58. HTMLSelectElement
    59. HTMLShadowElement
    60. HTMLSourceElement
    61. HTMLSpanElement
    62. HTMLStyleElement
    63. HTMLTableCaptionElement
    64. HTMLTableCellElement
    65. HTMLTableColElement
    66. HTMLTableDataCellElement
    67. HTMLTableElement
    68. HTMLTableHeaderCellElement
    69. HTMLTableRowElement
    70. HTMLTableSectionElement
    71. HTMLTemplateElement
    72. HTMLTextAreaElement
    73. HTMLTimeElement
    74. HTMLTitleElement
    75. HTMLTrackElement
    76. HTMLUListElement
    77. HTMLUnknownElement
    78. HTMLVideoElement
    79. HashChangeEvent
    80. History
    81. ImageData
    82. Location
    83. MessageChannel
    84. MessageEvent
    85. MessagePort
    86. Navigator
    87. NavigatorGeolocation
    88. NavigatorID
    89. NavigatorLanguage
    90. NavigatorOnLine
    91. NavigatorPlugins
    92. PageTransitionEvent
    93. Plugin
    94. PluginArray
    95. PopStateEvent
    96. PortCollection
    97. RadioNodeList
    98. Transferable
    99. ValidityState
    100. Window
    101. WindowBase64
    102. WindowEventHandlers
    103. WindowTimers