Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/browser/src/stack-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<data:${dataUriMatch[2]}>`,
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];

Expand Down
49 changes: 49 additions & 0 deletions packages/browser/test/tracekit/chromium.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<data:application/javascript>',
function: 'dynamicFn',
},
],
},
type: 'Error',
value: 'Error from data-uri module',
});
});
});
Loading