Overview
Access tracing through the browser context:Methods
start
Starts tracing.string
Trace name. If not specified, the trace name is generated from the test file name and title.
string
Trace title to display in the Trace Viewer.
boolean
default:"false"
Whether to capture screenshots during tracing.
boolean
default:"false"
Whether to capture DOM snapshots during tracing.
boolean
default:"false"
Whether to include source files in the trace.
Promise<void>
startChunk
Starts a new trace chunk. Useful for recording traces in multiple segments.string
Chunk name.
string
Chunk title to display in the Trace Viewer.
Promise<void>
stopChunk
Stops the current trace chunk and optionally saves it to a file.string
Path to save the trace file. If not specified, the trace is discarded.
Promise<void>
stop
Stops tracing and optionally saves it to a file.string
Path to save the trace file. If not specified, the trace is discarded.
Promise<void>
group
Creates a logical group in the trace for better organization.string
required
Group name.
{ file: string, line?: number, column?: number }
Source code location for the group.
Promise<void>
groupEnd
Ends the current trace group.Promise<void>
Examples
Basic tracing
Tracing with chunks
Grouping trace actions
Conditional tracing
Tracing with source files
Trace on failure
Viewing traces
After collecting traces, view them using the Playwright Trace Viewer:Configuration
Configure tracing inplaywright.config.ts:
'on': Record trace for each test'off': Do not record trace'retain-on-failure': Record trace for each test, but remove it if test passes'on-first-retry': Record trace only when retrying a test for the first time
