Skip to main content
Version: 1.15

Tracing

API for collecting and saving Playwright traces. Playwright traces can be opened in Trace Viewer after Playwright script runs.

Start recording a trace before performing actions. At the end, stop tracing and save it to a file.

await using var browser = playwright.Chromium.LaunchAsync();await using var context = await browser.NewContextAsync();await context.Tracing.StartAsync(new TracingStartOptions{  Screenshots: true,  Snapshots: true});var page = context.NewPageAsync();await page.GotoAsync("https://playwright.dev");await context.Tracing.StopAsync(new TracingStopOptions{  Path: "trace.zip"});

Tracing.StartAsync(options)#

  • options <TracingStartOptions?>
    • Name <string?> If specified, the trace is going to be saved into the file with the given name inside the tracesDir folder specified in BrowserType.LaunchAsync(options).#
    • Screenshots <bool?> Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.#
    • Snapshots <bool?> Whether to capture DOM snapshot on every action.#
  • returns: <void>#

Start tracing.

await using var browser = playwright.Chromium.LaunchAsync();await using var context = await browser.NewContextAsync();await context.Tracing.StartAsync(new TracingStartOptions{  Screenshots: true,  Snapshots: true});var page = context.NewPageAsync();await page.GotoAsync("https://playwright.dev");await context.Tracing.StopAsync(new TracingStopOptions{  Path: "trace.zip"});

Tracing.StartChunkAsync()#

Start a new trace chunk. If you'd like to record multiple traces on the same BrowserContext, use Tracing.StartAsync(options) once, and then create multiple trace chunks with Tracing.StartChunkAsync() and Tracing.StopChunkAsync(options).

await using var browser = playwright.Chromium.LaunchAsync();await using var context = await browser.NewContextAsync();await context.Tracing.StartAsync(new TracingStartOptions{  Screenshots: true,  Snapshots: true});var page = context.NewPageAsync();await page.GotoAsync("https://playwright.dev");
await context.Tracing.StartChunkAsync();await page.ClickAsync("text=Get Started");// Everything between StartChunkAsync and StopChunkAsync will be recorded in the trace.await context.Tracing.StopChunkAsync(new TracingStopChunkOptions{  Path: "trace1.zip"});
await context.Tracing.StartChunkAsync();await page.GotoAsync("http://example.com");// Save a second trace file with different actions.await context.Tracing.StopChunkAsync(new TracingStopChunkOptions{  Path: "trace2.zip"});

Tracing.StopAsync(options)#

  • options <TracingStopOptions?>
    • Path <string?> Export trace into the file with the given path.#
  • returns: <void>#

Stop tracing.

Tracing.StopChunkAsync(options)#

Stop the trace chunk. See Tracing.StartChunkAsync() for more details about multiple trace chunks.