Skip to content

Commit 3c37188

Browse files
committed
feat(browser): Handles data URIs in chrome stack frames
1 parent 8f4d56f commit 3c37188

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

packages/browser/src/stack-parsers.ts

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

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

64+
// at dynamicFn (data:application/javascript,export function dynamicFn() {...
65+
const chromeDataUriRegex = /at (.+?) ?\(data:(.+?),/;
66+
6467
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
6568
// We cannot call this variable `chrome` because it can conflict with global `chrome` variable in certain environments
6669
// See: https://github.com/getsentry/sentry-javascript/issues/6880
6770
const chromeStackParserFn: StackLineParserFn = line => {
71+
const dataUriMatch = line.match(chromeDataUriRegex);
72+
if (dataUriMatch) {
73+
return {
74+
filename: `<data:${dataUriMatch[2]}>`,
75+
function: dataUriMatch[1],
76+
};
77+
}
78+
6879
// If the stack line has no function name, we need to parse it differently
6980
const noFnParts = chromeRegexNoFnName.exec(line) as null | [string, string, string, string];
7081

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,4 +741,55 @@ 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
});
794+
795+

0 commit comments

Comments
 (0)