UNPKG

@sentry/browser

Version:
54 lines (50 loc) 1.84 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const browser = require('@sentry/core/browser'); const WINDOW = browser.GLOBAL_OBJ; const DEFAULT_LINES_OF_CONTEXT = 7; const INTEGRATION_NAME = "ContextLines"; const _contextLinesIntegration = ((options = {}) => { const contextLines = options.frameContextLines != null ? options.frameContextLines : DEFAULT_LINES_OF_CONTEXT; return { name: INTEGRATION_NAME, processEvent(event) { return addSourceContext(event, contextLines); } }; }); const contextLinesIntegration = browser.defineIntegration(_contextLinesIntegration); function addSourceContext(event, contextLines) { const doc = WINDOW.document; const htmlFilename = WINDOW.location && browser.stripUrlQueryAndFragment(WINDOW.location.href); if (!doc || !htmlFilename) { return event; } const exceptions = event.exception?.values; if (!exceptions?.length) { return event; } const html = doc.documentElement.innerHTML; if (!html) { return event; } const htmlLines = ["<!DOCTYPE html>", "<html>", ...html.split("\n"), "</html>"]; exceptions.forEach((exception) => { const stacktrace = exception.stacktrace; if (stacktrace?.frames) { stacktrace.frames = stacktrace.frames.map( (frame) => applySourceContextToFrame(frame, htmlLines, htmlFilename, contextLines) ); } }); return event; } function applySourceContextToFrame(frame, htmlLines, htmlFilename, linesOfContext) { if (frame.filename !== htmlFilename || !frame.lineno || !htmlLines.length) { return frame; } browser.addContextToFrame(htmlLines, frame, linesOfContext); return frame; } exports.applySourceContextToFrame = applySourceContextToFrame; exports.contextLinesIntegration = contextLinesIntegration; //# sourceMappingURL=contextlines.js.map