UNPKG

@grafana/faro-web-sdk

Version:

Faro instrumentations, metas, transports for web.

73 lines 3.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getStackFramesFromError = getStackFramesFromError; const faro_core_1 = require("@grafana/faro-core"); const buildStackFrame_1 = require("./buildStackFrame"); const const_1 = require("./const"); const getDataFromSafariExtensions_1 = require("./getDataFromSafariExtensions"); // Cap individual stack lines to bound runtime of the stack parsing regexes (avoid pathological backtracking on crafted input). const MAX_STACK_LINE_LENGTH = 1024; function getStackFramesFromError(error) { let lines = []; if (error.stacktrace) { lines = error.stacktrace.split(const_1.newLineString).filter((_line, idx) => idx % 2 === 0); } else if (error.stack) { lines = error.stack.split(const_1.newLineString); } const stackFrames = lines.reduce((acc, line, idx) => { if (line.length > MAX_STACK_LINE_LENGTH) { return acc; } let parts; let func; let filename; let lineno; let colno; if ((parts = const_1.webkitLineRegex.exec(line))) { func = parts[1]; filename = parts[2]; lineno = parts[3]; colno = parts[4]; if (filename === null || filename === void 0 ? void 0 : filename.startsWith(const_1.webkitEvalString)) { const submatch = const_1.webkitEvalRegex.exec(filename); if (submatch) { filename = submatch[1]; lineno = submatch[2]; colno = submatch[3]; } } filename = (filename === null || filename === void 0 ? void 0 : filename.startsWith(const_1.webkitAddressAtString)) ? filename.substring(const_1.webkitAddressAtStringLength) : filename; [func, filename] = (0, getDataFromSafariExtensions_1.getDataFromSafariExtensions)(func, filename); } else if ((parts = const_1.firefoxLineRegex.exec(line))) { func = parts[1]; filename = parts[3]; lineno = parts[4]; colno = parts[5]; if (!!filename && filename.includes(const_1.firefoxEvalString)) { const submatch = const_1.firefoxEvalRegex.exec(filename); if (submatch) { func = func || const_1.evalString; filename = submatch[1]; lineno = submatch[2]; } } else if (idx === 0 && !colno && (0, faro_core_1.isNumber)(error.columnNumber)) { colno = String(error.columnNumber + 1); } [func, filename] = (0, getDataFromSafariExtensions_1.getDataFromSafariExtensions)(func, filename); } if (filename || func) { acc.push((0, buildStackFrame_1.buildStackFrame)(filename, func, lineno ? Number(lineno) : undefined, colno ? Number(colno) : undefined)); } return acc; }, []); if (const_1.reactMinifiedRegex.test(error.message)) { return stackFrames.slice(1); } return stackFrames; } //# sourceMappingURL=getStackFramesFromError.js.map