Table of Contents

Interface ITracing

Namespace
Microsoft.Playwright
Assembly
Microsoft.Playwright.dll

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.

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

Methods

StartAsync(TracingStartOptions?)

Start tracing.

**Usage**

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

Parameters

options TracingStartOptions

Call options

Returns

Task

StartChunkAsync(TracingStartChunkOptions?)

Start a new trace chunk. If you'd like to record multiple traces on the same IBrowserContext, use StartAsync(TracingStartOptions?) once, and then create multiple trace chunks with StartChunkAsync(TracingStartChunkOptions?) and StopChunkAsync(TracingStopChunkOptions?).

**Usage**

using var playwright = await Playwright.CreateAsync();
var browser = await playwright.Chromium.LaunchAsync();
await using var context = await browser.NewContextAsync();
await context.Tracing.StartAsync(new()
{
  Screenshots = true,
  Snapshots = true
});
var page = await context.NewPageAsync();
await page.GotoAsync("https://playwright.dev");

await context.Tracing.StartChunkAsync(); await page.GetByText("Get Started").ClickAsync(); // Everything between StartChunkAsync and StopChunkAsync will be recorded in the trace. await context.Tracing.StopChunkAsync(new() { 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() { Path = "trace2.zip" });

Task StartChunkAsync(TracingStartChunkOptions? options = null)

Parameters

options TracingStartChunkOptions

Call options

Returns

Task

StopAsync(TracingStopOptions?)

Stop tracing.

Task StopAsync(TracingStopOptions? options = null)

Parameters

options TracingStopOptions

Call options

Returns

Task

StopChunkAsync(TracingStopChunkOptions?)

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

Task StopChunkAsync(TracingStopChunkOptions? options = null)

Parameters

options TracingStopChunkOptions

Call options

Returns

Task