Use case
Today tracing is all-or-nothing: it can only be enabled for a whole context via the tracing argument of New Context, producing one trace for everything that context ever did. Users debugging a single flaky test case, or wanting a small shareable trace of just one scenario, cannot start tracing mid-test, cannot stop it early, cannot give the trace a human-readable title for the trace viewer, and cannot include source files. The only workaround is restructuring suites so that the interesting steps run in their own dedicated context — invasive and often impossible.
Playwright's Tracing API supports exactly this: start/stop on demand, plus chunks — multiple separate trace files recorded within one tracing session, each covering only the actions between startChunk and stopChunk.
Proposed keyword / arguments
Start Tracing *, screenshots=True snapshots=True sources=False title=None name=None live=False
Stop Tracing path=None
Start Trace Chunk *, title=None name=None
Stop Trace Chunk path=None
Start Tracing (Setter) begins tracing on the current context. title names the trace in the trace viewer; sources=True embeds source files; live enables live-viewable traces; name prefixes intermediate trace files in the traces dir.
Stop Tracing (Getter) stops tracing, saves the zip to path (default: a generated file under the library's output directory) and returns the file path.
Start Trace Chunk / Stop Trace Chunk record only the actions in between into a separate trace file within the same tracing session, so one long-lived context can yield one small trace per scenario.
New Context
Start Tracing title=Login flow sources=True
Go To ${LOGIN_URL}
Start Trace Chunk title=Submit credentials
Fill Text id=user alice
Click id=submit
${chunk}= Stop Trace Chunk path=${OUTPUT_DIR}/traces/login-submit.zip
${trace}= Stop Tracing path=${OUTPUT_DIR}/traces/login-full.zip
Playwright API
Implementation notes
protobuf/playwright.proto: RPCs for start/stop/startChunk/stopChunk with the option fields.
node/playwright-wrapper: calls on the current context's tracing object; must coexist with the existing New Context tracing= mechanism (guard against double-start with a clear error). Note the library already wraps every keyword in tracing.group internally — chunk boundaries slot into that unchanged.
- Python: keywords in
Browser/keywords (natural fit: playwright_state.py or a new tracing module), docs, stub regen; atest verifying a valid trace zip is produced mid-context and that chunks contain only their own actions.
Backwards compatibility
Purely additive: four new keywords. The existing New Context tracing= shortcut keeps working unchanged; starting tracing twice is an explicit error rather than a behavior change.
Use case
Today tracing is all-or-nothing: it can only be enabled for a whole context via the
tracingargument ofNew Context, producing one trace for everything that context ever did. Users debugging a single flaky test case, or wanting a small shareable trace of just one scenario, cannot start tracing mid-test, cannot stop it early, cannot give the trace a human-readable title for the trace viewer, and cannot include source files. The only workaround is restructuring suites so that the interesting steps run in their own dedicated context — invasive and often impossible.Playwright's Tracing API supports exactly this: start/stop on demand, plus chunks — multiple separate trace files recorded within one tracing session, each covering only the actions between
startChunkandstopChunk.Proposed keyword / arguments
Start Tracing(Setter) begins tracing on the current context.titlenames the trace in the trace viewer;sources=Trueembeds source files;liveenables live-viewable traces;nameprefixes intermediate trace files in the traces dir.Stop Tracing(Getter) stops tracing, saves the zip topath(default: a generated file under the library's output directory) and returns the file path.Start Trace Chunk/Stop Trace Chunkrecord only the actions in between into a separate trace file within the same tracing session, so one long-lived context can yield one small trace per scenario.Playwright API
screenshots,snapshots,sources,title,name,live)Implementation notes
protobuf/playwright.proto: RPCs for start/stop/startChunk/stopChunk with the option fields.node/playwright-wrapper: calls on the current context'stracingobject; must coexist with the existingNew Context tracing=mechanism (guard against double-start with a clear error). Note the library already wraps every keyword intracing.groupinternally — chunk boundaries slot into that unchanged.Browser/keywords(natural fit:playwright_state.pyor a new tracing module), docs, stub regen; atest verifying a valid trace zip is produced mid-context and that chunks contain only their own actions.Backwards compatibility
Purely additive: four new keywords. The existing
New Context tracing=shortcut keeps working unchanged; starting tracing twice is an explicit error rather than a behavior change.