Implementation:Microsoft Playwright StackTrace
Appearance
Overview
StackTrace provides stack trace capture and parsing utilities for error reporting, API call attribution, and source mapping in Playwright's tracing system.
Description
This module offers:
captureRawStack()-- captures the current call stack as an array of raw stack frame strings with an increased stack trace limit (50 frames)parseStackFrame()-- parses a single stack frame string into a structuredStackFrameobject with file, line, column, and function namerewriteErrorMessage()-- replaces an error's message while preserving the stack trace- Stack frame filtering for internal Node.js frames
The parsing uses a comprehensive regex to handle various V8 stack trace formats including at Function.method (file:line:column), at file:line:column, and eval contexts.
Usage
Used throughout Playwright for error enhancement, API call attribution in traces, and the ManualPromise class.
Code Reference
Source Location
packages/playwright-core/src/utils/isomorphic/stackTrace.ts (201 lines)
Type and Function Signatures
export type RawStack = string[];
export type StackFrame = {
file: string;
line: number;
column: number;
function?: string;
};
export function captureRawStack(): RawStack;
export function parseStackFrame(text: string, pathSeparator: string, showInternalStackFrames: boolean): StackFrame | null;
export function rewriteErrorMessage(error: Error, newMessage: string): Error;
Import
import { captureRawStack, parseStackFrame, rewriteErrorMessage } from '../utils/isomorphic/stackTrace';
import type { StackFrame, RawStack } from '../utils/isomorphic/stackTrace';
I/O Contract
captureRawStack
- Input: none (captures from current call site)
- Output: array of stack frame strings
parseStackFrame
- Input: stack frame text, path separator, internal frame visibility flag
- Output:
StackFrameobject or null if unparseable
rewriteErrorMessage
- Input: Error object and new message string
- Output: same Error with rewritten message (stack trace preserved)
Related Pages
- Microsoft_Playwright_ManualPromise -- Uses captureRawStack
- Microsoft_Playwright_FfExecutionContext -- Uses rewriteErrorMessage
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment