Skip to content

Commit aab4276

Browse files
authored
feat(browser): Handles data URIs in chrome stack frames (#17292)
This PR copies what we did for Node (#17218) but for the Chromium stack parser.
1 parent 82f0cf9 commit aab4276

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

packages/browser/src/stack-parsers.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,22 @@ const chromeRegex =
6161

6262
const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
6363

64+
// Matches stack frames with data URIs instead of filename so we can still get the function name
65+
// Example: "at dynamicFn (data:application/javascript,export function dynamicFn() {..."
66+
const chromeDataUriRegex = /at (.+?) ?\(data:(.+?),/;
67+
6468
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
6569
// We cannot call this variable `chrome` because it can conflict with global `chrome` variable in certain environments
6670
// See: https://github.com/getsentry/sentry-javascript/issues/6880
6771
const chromeStackParserFn: StackLineParserFn = line => {
72+
const dataUriMatch = line.match(chromeDataUriRegex);
73+
if (dataUriMatch) {
74+
return {
75+
filename: `<data:${dataUriMatch[2]}>`,
76+
function: dataUriMatch[1],
77+
};
78+
}
79+
6880
// If the stack line has no function name, we need to parse it differently
6981
const noFnParts = chromeRegexNoFnName.exec(line) as null | [string, string, string, string];
7082

packages/browser/test/tracekit/chromium.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,53 @@ describe('Tracekit - Chrome Tests', () => {
741741
value: 'memory access out of bounds',
742742
});
743743
});
744+
745+
it('should correctly parse with data uris', () => {
746+
const DATA_URI_ERROR = {
747+
message: 'Error from data-uri module',
748+
name: 'Error',
749+
stack: `Error: Error from data-uri module
750+
at dynamicFn (data:application/javascript,export function dynamicFn() { throw new Error('Error from data-uri module');};:1:38)
751+
at loadDodgyModule (file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:8:5)
752+
at async callSomeFunction (file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:12:5)
753+
at async file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:16:5`,
754+
};
755+
756+
const ex = exceptionFromError(parser, DATA_URI_ERROR);
757+
758+
// This is really ugly but the wasm integration should clean up these stack frames
759+
expect(ex).toStrictEqual({
760+
stacktrace: {
761+
frames: [
762+
{
763+
colno: 5,
764+
filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs',
765+
function: '?',
766+
in_app: true,
767+
lineno: 16,
768+
},
769+
{
770+
colno: 5,
771+
filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs',
772+
function: 'async callSomeFunction',
773+
in_app: true,
774+
lineno: 12,
775+
},
776+
{
777+
colno: 5,
778+
filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs',
779+
function: 'loadDodgyModule',
780+
in_app: true,
781+
lineno: 8,
782+
},
783+
{
784+
filename: '<data:application/javascript>',
785+
function: 'dynamicFn',
786+
},
787+
],
788+
},
789+
type: 'Error',
790+
value: 'Error from data-uri module',
791+
});
792+
});
744793
});

0 commit comments

Comments
 (0)