getsentry / rust-sourcemap

A library for rust that implements basic sourcemap handling
Other
224 stars 27 forks source link

Sourcemap locations may be resolved incorrectly in Firefox #37

Open robertknight opened 2 years ago

robertknight commented 2 years ago

Please consider this issue an FYI for other Sentry users as much as anything else, since I think the fix will happen in Firefox.

We recently ran into a problem where JavaScript crash reports from Firefox were resolved to the wrong location in the original code. The issue turned out to be that Firefox expresses column numbers in stack traces differently than other browsers. Chrome and Safari report the column number in UTF-16 code units, whereas Firefox reports them in Unicode code points. From what I can tell, this package assumes UTF-16 code units. If a minified source bundle contains many characters (eg. emojis) that require multiple UTF-16 characters to encode, this can result in incorrectly resolved source locations when processing crash reports in Firefox.

I filed an issue at https://github.com/tc39/proposal-error-stacks/issues/42 and https://bugzilla.mozilla.org/show_bug.cgi?id=1746374 to try to find an upstream resolution.

mitsuhiko commented 2 years ago

I left a comment now on the tc39 proposal. I hope for now that Firefox reverts this behavior but the issue is known from our side. Since not all Firefox versions agree on the offset it's unfortunately a pretty frustrating situation right now that we do not want to try to make too many guesses about.

robertknight commented 2 years ago

Thanks for the update. For the benefit of anyone else who runs into this, a dumb workaround that we settled on is to configure our minifier to limit the length of lines in the output. This limits the blast radius of the problem.

From our Terser config:

terser({
  format: {
    // Strip *all* comments from minified output. This works around an issue
    // with column numbers in stack traces in Safari. See
    // https://bugs.webkit.org/show_bug.cgi?id=221548 and
    // https://github.com/hypothesis/client/issues/4045.
    comments: false,

    // Limit length of lines in output. This makes the minfied output easier
    // to examine in tools that struggle with long lines and limits the
    // impact of an issue with stack trace column numbers in Firefox.
    // See https://github.com/hypothesis/client/issues/4045.
    max_line_len: 1024,
  },
})