Playwright·Cookbook Field Manual
Part 05 · Operations & Advanced Card 29

Trace Viewer

Card 29: Trace Viewer

What This Pattern Solves

The config sets trace: 'on-first-retry' but no card teaches the viewer. When a test fails, the trace is your fastest path to root cause: it records every action, network request, screenshot, console log, and assertion — all on a scrubbable timeline. Without it, you are debugging blind.

How It Works

  1. Configure trace mode: trace: 'on-first-retry' — traces only recorded when a test retries.
  2. Run tests: Playwright writes trace files into test-results/.
  3. Open the trace: npx playwright show-trace <path> or click the trace icon in the HTML report.
  4. Navigate the viewer: scrub through actions, inspect network calls, view DOM snapshots, read console logs.

CLI Commands

npx playwright test --trace on
npx playwright show-trace test-results/.../trace.zip
npx playwright show-report

Trace Modes

ModeWhen traces are recorded
'off'Never
'on'Every test
'on-first-retry'Only when a test retries (recommended)
'retain-on-failure'On failure, cleaned up on success

Run This Example

pnpm test src/29-trace-viewer
npx playwright show-report

Prerequisites

Key Concepts

Live Demo

👇 This component is what the Playwright test interacts with:

Loading…

Run This Example

pnpm test src/29-trace-viewer