• Web APIs
  • Window
  • Instance properties
    1. credentialless Experimental
    2. devicePixelRatio
    3. documentPictureInPicture Experimental
    4. event Deprecated
    5. external Deprecated
    6. fence Experimental
    7. fullScreen Non-standard
    8. innerWidth
    9. launchQueue Experimental
    10. locationbar
    11. mozInnerScreenX Non-standard
    12. mozInnerScreenY Non-standard
    13. navigation Experimental
    14. orientation Deprecated
    15. originAgentCluster Experimental
    16. performance
    17. screenLeft
    18. scrollbars
    19. scrollMaxX Non-standard
    20. scrollMaxY Non-standard
    21. sessionStorage
    22. sharedStorage Experimental
    23. status Deprecated
    24. trustedTypes
    25. atob()
    26. back() Non-standard Deprecated
    27. blur() Deprecated
    28. captureEvents() Deprecated
    29. clearImmediate() Non-standard Deprecated
    30. confirm()
    31. dump() Non-standard
    32. find() Non-standard
    33. forward() Non-standard Deprecated
    34. getDefaultComputedStyle() Non-standard
    35. getScreenDetails() Experimental
    36. moveTo()
    37. prompt()
    38. queryLocalFonts() Experimental
    39. releaseEvents() Deprecated
    40. requestFileSystem() Non-standard Deprecated
    41. scroll()
    42. scrollByLines() Non-standard
    43. scrollByPages() Non-standard
    44. setImmediate() Non-standard Deprecated
    45. setResizable() Non-standard Deprecated
    46. showDirectoryPicker() Experimental
    47. showModalDialog() Non-standard Deprecated
    48. showOpenFilePicker() Experimental
    49. showSaveFilePicker() Experimental
    50. sizeToContent() Non-standard
    51. webkitConvertPointFromNodeToPage() Non-standard Deprecated
    52. webkitConvertPointFromPageToNode() Non-standard Deprecated
  • Events
    1. beforeprint
    2. cut
    3. error
    4. hashchange
    5. messageerror
    6. orientationchange Deprecated
    7. pageswap
    8. resize
    9. scrollsnapchange Experimental
    10. scrollsnapchanging Experimental
    11. unload Deprecated
    12. vrdisplayactivate Non-standard Deprecated
    13. vrdisplayconnect Non-standard Deprecated
    14. vrdisplaydeactivate Non-standard Deprecated
    15. vrdisplaydisconnect Non-standard Deprecated
    16. vrdisplaypresentchange Non-standard Deprecated
  • Inheritance
    1. ErrorEvent
    2. HTMLBRElement
    3. HTMLCanvasElement
    4. HTMLDialogElement
    5. HTMLEmbedElement
    6. HTMLFrameSetElement Deprecated
    7. HTMLHtmlElement
    8. HTMLLIElement
    9. HTMLMapElement
    10. HTMLMeterElement
    11. HTMLOptGroupElement
    12. HTMLParagraphElement
    13. HTMLQuoteElement
    14. HTMLSpanElement
    15. HTMLTableColElement
    16. HTMLTemplateElement
    17. HTMLTrackElement
    18. HashChangeEvent
    19. MessageChannel
    20. PageRevealEvent
    21. Plugin Deprecated
    22. PluginArray Deprecated
    23. ValidityState
    24. Worker.

      This is useful for debugging and for providing fallback error handling for unexpected situations.

  • Syntax

    Use the event name in methods like addEventListener(), or set an event handler property.

    js
    addEventListener("unhandledrejection", (event) => {});
    onunhandledrejection = (event) => {};
    

    Event type

    Event properties

    PromiseRejectionEvent.promise Read only

    The JavaScript Promise that was rejected.

    PromiseRejectionEvent.reason Read only

    A value or Promise.reject().

    Event handler aliases

    In addition to the Window interface, the event handler property onunhandledrejection is also available on the following targets:

    Usage notes

    Allowing the unhandledrejection event to bubble will eventually result in an error message being output to the console. You can prevent this by calling PromiseRejectionEvent; see Preventing default handling below for an example.

    Because this event can leak data, Promise rejections that originate from a cross-origin script won't fire this event.

    Examples

    Basic error logging

    This example logs information about the unhandled promise rejection to the console.

    js
    window.addEventListener("unhandledrejection", (event) => {
      console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
    });
    

    You can also use the onunhandledrejection event handler property to set up the event listener:

    js
    window.onunhandledrejection = (event) => {
      console.warn(`UNHANDLED PROMISE REJECTION: ${event.reason}`);
    };
    

    Preventing default handling

    Many environments (such as preventDefault() to cancel the event, preventing it from bubbling up to be handled by the runtime's logging code. This works because unhandledrejection is cancelable.

    js
    window.addEventListener("unhandledrejection", (event) => {
      / code for handling the unhandled rejection
      / …
    
      / Prevent the default handling (such as outputting the
      / error to the console)
    
      event.preventDefault();
    });
    

    Specifications

    Specification
    HTML
    # handler-window-onunhandledrejection

    Browser compatibility

    BCD tables only load in the browser

    See also