diff --git a/packages/browser/src/stack-parsers.ts b/packages/browser/src/stack-parsers.ts index d857b2e92b36..02c3a1f66af3 100644 --- a/packages/browser/src/stack-parsers.ts +++ b/packages/browser/src/stack-parsers.ts @@ -61,10 +61,22 @@ const chromeRegex = const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/; +// Matches stack frames with data URIs instead of filename so we can still get the function name +// Example: "at dynamicFn (data:application/javascript,export function dynamicFn() {..." +const chromeDataUriRegex = /at (.+?) ?\(data:(.+?),/; + // Chromium based browsers: Chrome, Brave, new Opera, new Edge // We cannot call this variable `chrome` because it can conflict with global `chrome` variable in certain environments // See: https://github.com/getsentry/sentry-javascript/issues/6880 const chromeStackParserFn: StackLineParserFn = line => { + const dataUriMatch = line.match(chromeDataUriRegex); + if (dataUriMatch) { + return { + filename: ``, + function: dataUriMatch[1], + }; + } + // If the stack line has no function name, we need to parse it differently const noFnParts = chromeRegexNoFnName.exec(line) as null | [string, string, string, string]; diff --git a/packages/browser/test/tracekit/chromium.test.ts b/packages/browser/test/tracekit/chromium.test.ts index 71cb950c147d..9a1cbd0abbe9 100644 --- a/packages/browser/test/tracekit/chromium.test.ts +++ b/packages/browser/test/tracekit/chromium.test.ts @@ -741,4 +741,53 @@ describe('Tracekit - Chrome Tests', () => { value: 'memory access out of bounds', }); }); + + it('should correctly parse with data uris', () => { + const DATA_URI_ERROR = { + message: 'Error from data-uri module', + name: 'Error', + stack: `Error: Error from data-uri module + at dynamicFn (data:application/javascript,export function dynamicFn() { throw new Error('Error from data-uri module');};:1:38) + at loadDodgyModule (file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:8:5) + at async callSomeFunction (file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:12:5) + at async file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs:16:5`, + }; + + const ex = exceptionFromError(parser, DATA_URI_ERROR); + + // This is really ugly but the wasm integration should clean up these stack frames + expect(ex).toStrictEqual({ + stacktrace: { + frames: [ + { + colno: 5, + filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs', + function: '?', + in_app: true, + lineno: 16, + }, + { + colno: 5, + filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs', + function: 'async callSomeFunction', + in_app: true, + lineno: 12, + }, + { + colno: 5, + filename: 'file:///Users/tim/Documents/Repositories/data-uri-tests/index.mjs', + function: 'loadDodgyModule', + in_app: true, + lineno: 8, + }, + { + filename: '', + function: 'dynamicFn', + }, + ], + }, + type: 'Error', + value: 'Error from data-uri module', + }); + }); });