Skip to main content

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()
{
Screenshots: true,
Snapshots: true
});
var page = context.NewPageAsync();
await page.GotoAsync("https://playwright.dev");
await context.Tracing.StopAsync(new()
{
Path: "trace.zip"
});

Tracing.StartAsync(options)

Added in: v1.12
  • 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?> If this option is true tracing will#
      • capture DOM snapshot on every action
      • record network activity
    • Sources <bool?> Whether to include source files for trace actions. Added in: v1.17#
    • Title <string?> Trace name to be shown in the Trace Viewer. Added in: v1.17#
  • returns: <void>#

Start tracing.

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

Tracing.StartChunkAsync(options)

Added in: v1.15
  • options <TracingStartChunkOptions?>
    • Title <string?> Trace name to be shown in the Trace Viewer. Added in: v1.17#
  • returns: <void>#

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(options) and Tracing.StopChunkAsync(options).

await using var browser = playwright.Chromium.LaunchAsync();
await using var context = await browser.NewContextAsync();
await context.Tracing.StartAsync(new()
{
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()
{
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"
});

Tracing.StopAsync(options)

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

Stop tracing.

Tracing.StopChunkAsync(options)

Added in: v1.15

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