Expand description
Programmatic parser for Playwright trace zip files (trace format v8, verified against traces recorded by the bundled Playwright 1.61 driver).
§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;
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 typedTraceEventenum. Unknown / future kinds surface asTraceEvent::Unknown.actions—before+ optionalinput+ zero-or-morelog+afterchunks reassembled into a logicalAction. The common case; use this unless you specifically need the raw event stream.network—NetworkEntrys from thetrace.networkHAR-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.methodcall as recorded in the trace. - Action
Error - Failure payload attached to an
AfterEvent. - Action
Stream - Streaming reassembly of
Actions from aTraceEventiterator. Usecrate::TraceReader::actionsto construct the typical case; public here so callers can wrap their own custom event source. - After
Event - Action-completion event.
- Before
Event - Action-start event. Pairs with a matching
AfterEventsharingcall_id. - Console
Event - Browser console output captured during the trace.
- Console
Location - Context
Options - Per-context metadata — appears once per trace as the first event
in
trace.trace. - Frame
Snapshot Event - 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.
- Header
Entry - Input
Event - 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
logevent. - Network
Entry - 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::pointandAfterEvent::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.
- Request
Post Data - Request
Snapshot - Resource
Override - 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. - Response
Content - Response
Snapshot - Screencast
Frame Event - Single screencast frame stored as a JPEG in
resources/<sha1>. - System
Event - System events (dialog, download, page open/close). Mirrors the
eventchunk type in the trace. - Trace
Reader - Streaming reader over a Playwright trace zip.
- Viewport
Enums§
- Trace
Error - Trace
Event - Strongly-typed variants for the event kinds this version of the
parser models. Unknown / unmodelled kinds surface as
TraceEvent::Unknownto preserve the underlying JSON.
Functions§
- open
- Convenience wrapper for
TraceReader::openover a file on disk.