123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import { createStackParser } from '@sentry/utils';
- const UNKNOWN_FUNCTION = '?';
- const OPERA10_PRIORITY = 10;
- const OPERA11_PRIORITY = 20;
- const CHROME_PRIORITY = 30;
- const WINJS_PRIORITY = 40;
- const GECKO_PRIORITY = 50;
- function createFrame(filename, func, lineno, colno) {
- const frame = {
- filename,
- function: func,
- in_app: true, // All browser frames are considered in_app
- };
- if (lineno !== undefined) {
- frame.lineno = lineno;
- }
- if (colno !== undefined) {
- frame.colno = colno;
- }
- return frame;
- }
- const chromeRegex =
- /^\s*at (?:(.+?\)(?: \[.+\])?|.*?) ?\((?:address at )?)?(?:async )?((?:<anonymous>|[-a-z]+:|.*bundle|\/)?.*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i;
- const chromeEvalRegex = /\((\S*)(?::(\d+))(?::(\d+))\)/;
- const chrome = line => {
- const parts = chromeRegex.exec(line);
- if (parts) {
- const isEval = parts[2] && parts[2].indexOf('eval') === 0;
- if (isEval) {
- const subMatch = chromeEvalRegex.exec(parts[2]);
- if (subMatch) {
-
- parts[2] = subMatch[1];
- parts[3] = subMatch[2];
- parts[4] = subMatch[3];
- }
- }
-
-
- const [func, filename] = extractSafariExtensionDetails(parts[1] || UNKNOWN_FUNCTION, parts[2]);
- return createFrame(filename, func, parts[3] ? +parts[3] : undefined, parts[4] ? +parts[4] : undefined);
- }
- return;
- };
- const chromeStackLineParser = [CHROME_PRIORITY, chrome];
- const geckoREgex =
- /^\s*(.*?)(?:\((.*?)\))?(?:^|@)?((?:[-a-z]+)?:\/.*?|\[native code\]|[^@]*(?:bundle|\d+\.js)|\/[\w\-. /=]+)(?::(\d+))?(?::(\d+))?\s*$/i;
- const geckoEvalRegex = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
- const gecko = line => {
- const parts = geckoREgex.exec(line);
- if (parts) {
- const isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
- if (isEval) {
- const subMatch = geckoEvalRegex.exec(parts[3]);
- if (subMatch) {
-
- parts[1] = parts[1] || 'eval';
- parts[3] = subMatch[1];
- parts[4] = subMatch[2];
- parts[5] = '';
- }
- }
- let filename = parts[3];
- let func = parts[1] || UNKNOWN_FUNCTION;
- [func, filename] = extractSafariExtensionDetails(func, filename);
- return createFrame(filename, func, parts[4] ? +parts[4] : undefined, parts[5] ? +parts[5] : undefined);
- }
- return;
- };
- const geckoStackLineParser = [GECKO_PRIORITY, gecko];
- const winjsRegex = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:[-a-z]+):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
- const winjs = line => {
- const parts = winjsRegex.exec(line);
- return parts
- ? createFrame(parts[2], parts[1] || UNKNOWN_FUNCTION, +parts[3], parts[4] ? +parts[4] : undefined)
- : undefined;
- };
- const winjsStackLineParser = [WINJS_PRIORITY, winjs];
- const opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i;
- const opera10 = line => {
- const parts = opera10Regex.exec(line);
- return parts ? createFrame(parts[2], parts[3] || UNKNOWN_FUNCTION, +parts[1]) : undefined;
- };
- const opera10StackLineParser = [OPERA10_PRIORITY, opera10];
- const opera11Regex =
- / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^)]+))\(.*\))? in (.*):\s*$/i;
- const opera11 = line => {
- const parts = opera11Regex.exec(line);
- return parts ? createFrame(parts[5], parts[3] || parts[4] || UNKNOWN_FUNCTION, +parts[1], +parts[2]) : undefined;
- };
- const opera11StackLineParser = [OPERA11_PRIORITY, opera11];
- const defaultStackLineParsers = [chromeStackLineParser, geckoStackLineParser, winjsStackLineParser];
- const defaultStackParser = createStackParser(...defaultStackLineParsers);
- const extractSafariExtensionDetails = (func, filename) => {
- const isSafariExtension = func.indexOf('safari-extension') !== -1;
- const isSafariWebExtension = func.indexOf('safari-web-extension') !== -1;
- return isSafariExtension || isSafariWebExtension
- ? [
- func.indexOf('@') !== -1 ? func.split('@')[0] : UNKNOWN_FUNCTION,
- isSafariExtension ? `safari-extension:${filename}` : `safari-web-extension:${filename}`,
- ]
- : [func, filename];
- };
- export { chromeStackLineParser, defaultStackLineParsers, defaultStackParser, geckoStackLineParser, opera10StackLineParser, opera11StackLineParser, winjsStackLineParser };
|