Parse
Extract structured data from Playwright trace.zip files.
The .parse() stage reads a Playwright trace archive and extracts all the data needed for video generation.
Basic usage
import { Recast } from 'playwright-recast'
const pipeline = Recast
.from('./test-results/trace.zip')
.parse()You can also point to a directory containing trace files:
const pipeline = Recast
.from('./test-results/')
.parse()What gets extracted
The parser reads the trace.zip and produces a structured representation containing:
| Data | Source | Used by |
|---|---|---|
| Actions | User interactions (click, fill, type, navigation) | Speed processing, click effects, auto-zoom |
| Screenshots | Frame-by-frame page captures | Video frames |
| Network events | API calls, resource loading | Speed classification (network wait) |
| Cursor positions | Mouse coordinates at each action | Cursor overlay, click effects, auto-zoom |
| BDD step titles | playwright-bdd Gherkin step names | Subtitle generation via .subtitlesFromTrace() |
CLI equivalent
# Parse is implicit in CLI mode — it always runs
npx playwright-recast -i ./test-results/trace.zip -o demo.mp4Source video resolution
The renderer needs a source .mp4/.webm to apply speed, zoom, overlays, and subtitles against. Two layouts are supported:
- Sibling
.webm(preferred) — when your Playwright config enablesrecordVideo(e.g.use: { video: 'on' }), the trace's sibling.webmis auto-discovered. Native frame rate, best quality. - Standalone
trace.zip— when no sibling.webmexists (trace downloaded from the trace viewer, or test run withoutrecordVideo), the pipeline assembles a CFR 25fps.mp4from the screencast JPEG frames stored inside the trace. Variable capture cadence —.webmis preferred when available.
Sharp text when zooming
A zoom enlarges source pixels, so a 1920px recording rendered at 1440p with a 1.8x zoom upscales text 2.4x and it goes soft. Record at a higher device scale instead:
// playwright.config.ts
import { defineConfig } from '@playwright/test'
import { recastVideo } from 'playwright-recast/config'
export default defineConfig({
use: {
...recastVideo({ viewport: { width: 1920, height: 1080 }, scale: 2 }),
trace: 'on',
},
})The page still lays out at 1920x1080, but the video is recorded at 3840x2160. recastVideo() sets the three things that have to agree, each of which fails silently on its own: --force-device-scale-factor (headless Chromium ignores deviceScaleFactor for the video), video.size of viewport x scale (Playwright pads a smaller frame with gray instead of scaling it), and headless mode (headed Chromium follows the OS display scale). Decimal scales work: for a sharp 1.8x zoom into 1440p, scale: 2.4 records 4608x2592. The scale is rounded up to the next one that gives whole, even device pixels (1.3334 records at 1.35 for 1920x1080), since only those record without gray padding or rescaling. In general, scale = max(1, max zoom x max(output width / viewport width, output height / viewport height)). Chromium only.
A higher scale costs render time and disk, growing with the recorded pixels (scale²). The render grows less than that, since voiceover and timing don't depend on it: 2 -> 2.4 is 44% more pixels and rendered 25% slower on a 3.5-minute screencast.
The renderer warns once the source is upscaled by more than 1.25x at the tightest zoom, and names the recording size that would be sharp.
Tips
- The trace file must be generated with Playwright's tracing enabled (
--trace onor viaplaywright.config.ts). .parse()should always be the first stage after.from(). Other stages depend on the parsed trace data.- Parsing is fast — the trace is read once and the structured data is passed through the pipeline.