Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright StackTrace

From Leeroopedia

Template:Implementation Page

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 structured StackFrame object with file, line, column, and function name
  • rewriteErrorMessage() -- 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: StackFrame object or null if unparseable

rewriteErrorMessage

  • Input: Error object and new message string
  • Output: same Error with rewritten message (stack trace preserved)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment