Pluggable integrations that enhance Sentry JavaScript SDKs with additional error tracking, monitoring, and debugging capabilities.
—
Browser-only integration that adds source context lines to stack frames pointing to inline JavaScript code in HTML pages. This integration helps debug errors in inline scripts that cannot be accessed by Sentry's backend for context collection.
/**
* Collects source context lines for inline JavaScript in HTML pages
* @param options - Configuration for context line collection
* @returns Integration instance that adds context to frames
*/
function contextLinesIntegration(options?: ContextLinesOptions): Integration;
interface ContextLinesOptions {
/** Number of context lines for each frame. Defaults to 7. Set to 0 to disable. */
frameContextLines?: number;
}/**
* Legacy class-based context lines integration
* @deprecated Use contextLinesIntegration() instead
*/
class ContextLines implements Integration {
constructor(options?: { frameContextLines?: number });
name: string;
processEvent(event: Event): Event;
}Controls the number of source lines to include around each frame:
Only processes stack frames that point to:
The integration:
document.documentElement.innerHTMLThis integration:
document and windowimport { contextLinesIntegration } from '@sentry/integrations';
import * as Sentry from '@sentry/browser';
// Default 7 lines of context
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
contextLinesIntegration()
]
});
// More context lines for better debugging
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
contextLinesIntegration({
frameContextLines: 15
})
]
});
// Minimal context for performance
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
contextLinesIntegration({
frameContextLines: 3
})
]
});
// Disable context collection
Sentry.init({
dsn: 'YOUR_DSN',
integrations: [
contextLinesIntegration({
frameContextLines: 0
})
]
});The integration reconstructs the HTML document structure:
<!DOCTYPE html>
<html>
<head>
<title>My App</title>
</head>
<body>
<script>
function buggyFunction() {
throw new Error('Inline script error'); // Line gets context
}
buggyFunction();
</script>
</body>
</html>When an error occurs in the inline script, the integration adds context lines showing the surrounding HTML and JavaScript code.
/**
* Applies source context to a single frame (exported for testing)
* @param frame - Stack frame to process
* @param htmlLines - Array of HTML source lines
* @param htmlFilename - Current page filename
* @param linesOfContext - Number of context lines to include
* @returns Frame with added context
*/
function applySourceContextToFrame(
frame: StackFrame,
htmlLines: string[],
htmlFilename: string,
linesOfContext: number
): StackFrame;This integration is particularly valuable for:
This integration complements Sentry's backend context collection by handling the specific case of inline JavaScript that cannot be accessed remotely.
Install with Tessl CLI
npx tessl i tessl/npm-sentry--integrations