Skip to content

Commit 2466221

Browse files
committed
Simplify function and add appropriate comment
1 parent 8053a19 commit 2466221

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

packages/browser/src/tracekit.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* largely modified and is now maintained as part of Sentry JS SDK.
44
*/
55

6-
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
6+
/* eslint-disable @typescript-eslint/no-unsafe-member-access, max-lines */
77

88
/**
99
* An object representing a single stack frame.
@@ -124,13 +124,10 @@ function computeStackTraceFromStackProp(ex: any): StackTrace | null {
124124
// Arpad: Working with the regexp above is super painful. it is quite a hack, but just stripping the `address at `
125125
// prefix here seems like the quickest solution for now.
126126
let url = parts[2] && parts[2].indexOf('address at ') === 0 ? parts[2].substr('address at '.length) : parts[2];
127-
128127
// Kamil: One more hack won't hurt us right? Understanding and adding more rules on top of these regexps right now
129128
// would be way too time consuming. (TODO: Rewrite whole RegExp to be more readable)
130129
let func = parts[1] || UNKNOWN_FUNCTION;
131-
if (isSafariExtension(func) || isSafariWebExtension(func)) {
132-
[func, url] = extractSafariExtensionDetails(func, url);
133-
}
130+
[func, url] = extractSafariExtensionDetails(func, url);
134131

135132
element = {
136133
url,
@@ -165,10 +162,7 @@ function computeStackTraceFromStackProp(ex: any): StackTrace | null {
165162

166163
let url = parts[3];
167164
let func = parts[1] || UNKNOWN_FUNCTION;
168-
169-
if (isSafariExtension(func) || isSafariWebExtension(func)) {
170-
[func, url] = extractSafariExtensionDetails(func, url);
171-
}
165+
[func, url] = extractSafariExtensionDetails(func, url);
172166

173167
element = {
174168
url,
@@ -254,13 +248,36 @@ function computeStackTraceFromStacktraceProp(ex: any): StackTrace | null {
254248
};
255249
}
256250

257-
const isSafariExtension = (func: string): boolean => func.indexOf('safari-extension') !== -1;
258-
const isSafariWebExtension = (func: string): boolean => func.indexOf('safari-web-extension') !== -1;
251+
/**
252+
* Safari web extensions, starting version unknown, can produce "frames-only" stacktraces.
253+
* What it means, is that instead of format like:
254+
*
255+
* Error: wat
256+
* at function@url:row:col
257+
* at function@url:row:col
258+
* at function@url:row:col
259+
*
260+
* it produces something like:
261+
*
262+
* function@url:row:col
263+
* function@url:row:col
264+
* function@url:row:col
265+
*
266+
* Because of that, it won't be captured by `chrome` RegExp and will fall into `Gecko` branch.
267+
* This function is extracted so that we can use it in both places without duplicating the logic.
268+
* Unfortunatelly "just" changing RegExp is too complicated now and making it pass all tests
269+
* and fix this case seems like an impossible, or at least way too time-consuming task.
270+
*/
259271
const extractSafariExtensionDetails = (func: string, url: string): [string, string] => {
260-
return [
261-
func.indexOf('@') !== -1 ? func.split('@')[0] : UNKNOWN_FUNCTION,
262-
isSafariExtension(func) ? `safari-extension:${url}` : `safari-web-extension:${url}`,
263-
];
272+
const isSafariExtension = func.indexOf('safari-extension') !== -1;
273+
const isSafariWebExtension = func.indexOf('safari-web-extension') !== -1;
274+
275+
return isSafariExtension || isSafariWebExtension
276+
? [
277+
func.indexOf('@') !== -1 ? func.split('@')[0] : UNKNOWN_FUNCTION,
278+
isSafariExtension ? `safari-extension:${url}` : `safari-web-extension:${url}`,
279+
]
280+
: [func, url];
264281
};
265282

266283
/** Remove N number of frames from the stack */

0 commit comments

Comments
 (0)