Skip to main content

Overview

The Trace Viewer is a post-mortem debugging tool that allows you to explore a recorded trace of your test execution. It captures everything: actions, screenshots, network requests, console logs, and more. Unlike the Inspector which debugs live execution, Trace Viewer analyzes what already happened.

Recording Traces

During Test Execution

Enable tracing in your Playwright config:
playwright.config.ts

Trace Modes

string

Via Command Line

Override config settings:

In Test Code

Programmatically control tracing:

Opening Traces

Show Trace Command

The primary way to view traces:
This opens the Trace Viewer UI where you can:
  • Drag and drop trace files
  • Paste trace URLs
  • Browse to trace files

With Trace File

With Trace URL

Serve Trace on Network

Open trace in a browser tab:
This starts an HTTP server and opens the trace in your default browser.

Browser Selection

Choose which browser to display the trace viewer in:
  • chromium (default)
  • firefox or ff
  • webkit or wk

Trace Viewer Interface

The Trace Viewer provides a comprehensive timeline view:

Action Timeline

Left sidebar showing all actions:
  • Navigation events
  • Clicks and inputs
  • Assertions
  • API calls
  • Waits and timeouts
Each action displays:
  • Duration
  • Success/failure status
  • Associated logs

Action Details

Click any action to see:
  • Method called (e.g., page.click())
  • Selector used
  • Parameters passed
  • Stack trace
  • Source code location

Metadata Panel

Top section shows:
  • Test name and file
  • Browser and platform
  • Duration and status
  • Retry attempt number

Advanced Trace Features

Filtering Actions

Use the filter box to find specific actions:

Snapshots and Screenshots

The Trace Viewer captures:
  • Before snapshot: DOM state before each action
  • After snapshot: DOM state after each action
  • Screenshots: Visual representation at each step
Snapshots are interactive - you can click elements to copy selectors and explore the DOM.

Network Tab Analysis

Investigate network issues:
In the trace viewer:
  1. Open the Network tab
  2. See all requests with timing
  3. Check for failed requests (red)
  4. Inspect request/response data

Console Logs

All browser console output is captured:

Trace Implementation Details

Based on /home/daytona/workspace/source/packages/playwright-core/src/server/trace/viewer/traceViewer.ts:154, the trace viewer:
  1. Starts an HTTP server to serve trace files
  2. Validates trace paths - supports local files, directories, and URLs
  3. Synthesizes trace descriptors for directory-based traces
  4. Launches a browser (or uses an existing one) to display the UI
  5. Routes trace file requests through the server
  6. Handles live trace updates when --stdin flag is used

Trace File Formats

Traces can be:
  • ZIP files (.zip) - Standard format containing all trace data
  • JSON files (.json) - Trace manifest/descriptor
  • Directories - Unzipped trace with multiple files

Using Traces in CI/CD

Playwright Cloud

Storing Artifacts

playwright.config.ts

GitHub Actions Example

.github/workflows/tests.yml
Download the artifacts and view locally:

Performance Considerations

Tracing adds overhead to test execution:
  • Disk space: 1-10 MB per test (with screenshots)
  • Execution time: 10-20% slower
  • Use on-first-retry to minimize impact

Optimizing Trace Size

Trace Viewer Options

Example Workflows

Debug Failed CI Test

Compare Before/After

Share Traces

See Also