The Trace Viewer is a standalone browser-based application for inspecting .zip trace archives produced by Playwright's tracing API. It provides a post-mortem debugging experience by rendering recorded actions, DOM snapshots, screenshots, network traffic, console output, and source code in an interactive interface.
The Trace Viewer consists of a Node.js backend that serves trace data and a React frontend that visualizes it.
Diagram: Trace Viewer System Overview
Sources: packages/playwright-core/cli.js1-20 packages/trace-viewer/src/ui/workbenchLoader.tsx26-37 packages/trace-viewer/src/ui/workbench.tsx67-72
The Trace Viewer is launched via the show-trace command. The server infrastructure is responsible for:
The WorkbenchLoader component manages the initial loading state. It supports:
.zip files dropped into the browser packages/trace-viewer/src/ui/workbenchLoader.tsx88-91TestServer via WebSocket when running in "server mode" packages/trace-viewer/src/ui/workbenchLoader.tsx111-121Sources: packages/trace-viewer/src/ui/workbenchLoader.tsx102-174 tests/config/traceViewerFixtures.ts153-186
The Workbench is the root UI component that composes the layout panels using SplitView and TabbedPane.
Diagram: Workbench Component Tree
Sources: packages/trace-viewer/src/ui/workbench.tsx67-210 packages/trace-viewer/src/ui/snapshotTab.tsx45-104
The ActionList packages/trace-viewer/src/ui/actionList.tsx51-129 renders the hierarchical tree of actions recorded during the trace.
buildActionTree to convert a flat list of ActionTraceEventInContext into a nested ActionTreeItem structure packages/trace-viewer/src/ui/actionList.tsx66page.getByRole('button')) packages/trace-viewer/src/ui/actionList.tsx145isVisible callback packages/trace-viewer/src/ui/actionList.tsx86-95Sources: packages/trace-viewer/src/ui/actionList.tsx51-167 packages/trace-viewer/src/ui/workbench.tsx104-114
The SnapshotTabsView packages/trace-viewer/src/ui/snapshotTab.tsx45-104 is responsible for rendering DOM snapshots. It manages the "Action", "Before", and "After" tabs to show state transitions.
The viewer uses a double-iframe strategy in SnapshotView to prevent flickering when switching between actions packages/trace-viewer/src/ui/snapshotTab.tsx115-161
extendSnapshot constructs URLs for the snapshot HTML and metadata (snapshotInfo) packages/trace-viewer/src/ui/snapshotTab.tsx63-66fetchSnapshotInfo to correctly size the iframe packages/trace-viewer/src/ui/snapshotTab.tsx126When isInspecting is enabled, the SnapshotView enables element picking. It uses the InjectedScript and Recorder classes to generate selectors for elements hovered in the snapshot packages/trace-viewer/src/ui/snapshotTab.tsx25-26
Sources: packages/trace-viewer/src/ui/snapshotTab.tsx45-161 packages/playwright-core/src/server/trace/recorder/tracing.ts128
Sources: packages/trace-viewer/src/ui/timeline.tsx30 packages/trace-viewer/src/ui/filmStrip.tsx38-50
The SourceTab packages/trace-viewer/src/ui/sourceTab.tsx73-124 displays the test code. It highlights the line corresponding to the selected action and provides a stack trace navigator via StackTraceView packages/trace-viewer/src/ui/sourceTab.tsx122 It uses CodeMirrorWrapper for syntax highlighting and can open the file in VS Code via vscode:// protocol links packages/trace-viewer/src/ui/sourceTab.tsx100
The ErrorsTab packages/trace-viewer/src/ui/errorsTab.tsx aggregates all errors encountered during the trace. It provides error grouping and consolidated views of associated actions packages/trace-viewer/src/ui/workbench.tsx22
The NetworkTab packages/trace-viewer/src/ui/networkTab.tsx provides a grid view of all network resources. It supports sorting by columns like "Name", "Method", "Status", and "Duration". Selecting a resource opens the detailed resource view.
Table: NetworkTab Columns
| Column | Description |
|---|---|
name | File name and URL |
method | HTTP method (GET, POST, etc.) |
status | HTTP status code |
duration | Time taken for the request |
size | Transferred resource size |
Sources: packages/trace-viewer/src/ui/networkTab.tsx25 packages/trace-viewer/src/ui/sourceTab.tsx73-124 packages/trace-viewer/src/ui/workbench.tsx79-91
Diagram: Trace Data Flow
Sources: packages/playwright-core/src/server/trace/recorder/tracing.ts164-182 packages/trace-viewer/src/ui/workbenchLoader.tsx128-144 packages/trace-viewer/src/ui/workbench.tsx67-72