Skip to content

feat(browser): Handles data URIs in chrome stack frames #17292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions packages/browser/src/stack-parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,21 @@ const chromeRegex =

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

// at dynamicFn (data:application/javascript,export function dynamicFn() {...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if I understand this comment, is dynamicFn important to this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, this is just the example string that is being matched I guess, makes sense then!

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',
});
});
});