Skip to main content

Crate playwright_rs_trace

Crate playwright_rs_trace 

Source
Expand description

Programmatic parser for Playwright trace zip files (format v8, matching Playwright 1.59.x).

§When to reach for this crate

Pairs with the producer side, playwright-rs::Tracing (which writes .trace.zip files during a test run). This crate is the consumer side: a streaming, no-Playwright-server-required parser for those files. Typical users:

  • CI bots that comment on PRs with “test X failed at this Locator”
  • Dashboards that aggregate flaky-test root causes across runs
  • AI agent feedback loops that learn from past trace failures
  • Post-mortem analyzers run from a Rust binary or xtask

No runtime dependency on the main playwright-rs crate — pull in only this crate (typically as a [dev-dependencies] entry) when you want to read traces.

§Quick example

use playwright_rs_trace::{open, TraceEvent};

let mut reader = open("trace.zip")?;
println!(
    "trace v{} from {}",
    reader.context().version,
    reader.context().browser_name,
);

for action in reader.actions()? {
    let action = action?;
    if action.error.is_some() {
        eprintln!(
            "failed: {}.{} ({:?})",
            action.class, action.method, action.error,
        );
    }
}

The reader is a streaming iterator — events / actions are yielded lazily as the underlying zip stream is read, so a large trace doesn’t need to fit in memory before processing begins.

§Four streaming entry points on TraceReader

  • raw_events — every JSONL line as raw JSON. Forward-compat escape hatch for callers dispatching on event kinds we don’t model.
  • events — same lines parsed into a typed TraceEvent enum. Unknown / future kinds surface as TraceEvent::Unknown.
  • actionsbefore + optional input + zero-or-more log + after chunks reassembled into a logical Action. The common case; use this unless you specifically need the raw event stream.
  • networkNetworkEntrys from the trace.network HAR-shape stream (request / response pairs). Independent of the action stream — collect-and-sort if you need a merged chronological view.

§Forward compatibility

Every JSONL line is preserved losslessly via TraceReader::raw_events. The typed iterators (TraceReader::events, TraceReader::actions) deserialize what the parser models and route anything else to TraceEvent::Unknown so nothing is silently dropped.

See the crate README.md for the full slice-plan and roadmap.

Structs§

Action
A logical action — class.method call as recorded in the trace.
ActionError
Failure payload attached to an AfterEvent.
ActionStream
Streaming reassembly of Actions from a TraceEvent iterator. Use crate::TraceReader::actions to construct the typical case; public here so callers can wrap their own custom event source.
AfterEvent
Action-completion event.
BeforeEvent
Action-start event. Pairs with a matching AfterEvent sharing call_id.
ConsoleEvent
Browser console output captured during the trace.
ConsoleLocation
ContextOptions
Per-context metadata — appears once per trace as the first event in trace.trace.
FrameSnapshotEvent
Per-frame DOM snapshot. Includes the full HTML payload — these can be sizeable; callers iterating on snapshots for many frames should expect the per-event size to dominate the overall trace memory budget.
HeaderEntry
InputEvent
Optional input-coordinate / input-snapshot reference attached to an in-flight action.
LogEvent
Log line emitted during an in-flight action.
LogLine
One log line attached to an action via the log event.
NetworkEntry
One entry from trace.network — a HAR-like resource snapshot recording a single HTTP request/response pair (or a single redirect step in a chain).
Point
2D coordinates for input events and click targets. Used in InputEvent::point and AfterEvent::point.
RawEvent
A single event from the trace, preserved as the underlying JSON object. Forward-compat escape hatch for callers who need to dispatch on event kinds the parser doesn’t model yet.
RequestPostData
RequestSnapshot
ResourceOverride
External resource reference used by a snapshot. Either a SHA-1 hash (resolved through the zip’s resources/ directory) or an internal reference identifier the trace viewer reassembles.
ResponseContent
ResponseSnapshot
ScreencastFrameEvent
Single screencast frame stored as a JPEG in resources/<sha1>.
SystemEvent
System events (dialog, download, page open/close). Mirrors the event chunk type in the trace.
TraceReader
Streaming reader over a Playwright trace zip.
Viewport

Enums§

TraceError
TraceEvent
Strongly-typed variants for the event kinds this version of the parser models. Unknown / unmodelled kinds surface as TraceEvent::Unknown to preserve the underlying JSON.

Functions§

open
Convenience wrapper for TraceReader::open over a file on disk.

Type Aliases§

Result