getsentry / sentry-javascript

Official Sentry SDKs for JavaScript
https://sentry.io
MIT License
7.97k stars 1.57k forks source link

Stack trace lost when capturing DOMException #4085

Closed nowylie closed 2 years ago

nowylie commented 3 years ago

Package + Version

Version:

6.13.3

Description

This is related to #3119

When calling captureException with a DOMException the stack trace of the error is lost.

The code at line 76 of eventbuilder.ts currently has a comment:

if (isDOMError(exception as DOMError) || isDOMException(exception as DOMException)) {
    // If it is a DOMError or DOMException (which are legacy APIs, but still supported in some browsers)
    // then we just extract the name, code, and message, as they don't provide anything else
    // https://developer.mozilla.org/en-US/docs/Web/API/DOMError
    // https://developer.mozilla.org/en-US/docs/Web/API/DOMException
    ...

Which I believe is incorrect. DOMError is a legacy API but I don't believe DOMException is. According to 3.14.1. DOMException custom bindings it is expected that DOMException should be an instance of Error and have an associated stack trace. I have confirmed that this is the case in current versions of Safari/Edge/Firefox/Chrome. This is not the case in IE11 though.

I am happy to submit a PR to fix this issue but wanted to get some guidance first.

The fixes I've considered so far are:

AbhiPrasad commented 2 years ago

Hey thanks for writing in. A PR would be great, we can help with testing and docs.