Skip to Content
API Reference

Recast Class

Complete API reference for the Recast pipeline class — static methods, chainable stages, and terminal operations

The Recast class (exported as Pipeline internally) is the entry point for building video pipelines. It is immutable — every method returns a new pipeline instance. Nothing executes until a terminal operation is called.

import { Recast } from 'playwright-recast'

Static Methods

Recast.from(source)

Create a new pipeline from a trace directory or zip file path.

const pipeline = Recast.from('./test-results/trace.zip')
ParameterTypeDescription
sourcestringPath to a .zip trace file or directory containing trace files

Returns: Pipeline


Chainable Methods

All chainable methods return a new Pipeline instance. The original pipeline is not modified.

.parse()

Parse the Playwright trace into structured data (actions, frames, network, cursor positions).

.parse()

Must be called before any other processing stage. Extracts ParsedTrace from the trace zip.


.hideSteps(predicate)

Filter out steps matching the predicate. Hidden steps do not appear in the output video.

.hideSteps(action => action.keyword === 'Given' && action.text?.includes('logged in'))
ParameterTypeDescription
predicate(action: TraceAction) => booleanReturns true for actions to hide

.speedUp(config)

Adjust video speed based on trace activity classification.

.speedUp({
  duringIdle: 4.0,
  duringUserAction: 1.0,
  duringNetworkWait: 2.0,
  duringNavigation: 2.0,
  minSegmentDuration: 500,
  maxSpeed: 8.0,
})
OptionTypeDefaultDescription
duringIdlenumber4.0Speed during idle periods
duringUserActionnumber1.0Speed during user actions
duringNetworkWaitnumber2.0Speed while waiting for network
duringNavigationnumber2.0Speed during page loads
minSegmentDurationnumber500Minimum segment duration (ms) before speed change
maxSpeednumber100.0Maximum speed multiplier
rulesSpeedRule[]—Custom speed rules (evaluated first)
segmentsArray<{startMs, endMs, speed}>—Pre-built speed segments (bypasses classification)
recordingPageIdstring—Filter actions to this page ID
postFastForwardSettleMsnumber0Extra delay after fast-forward zones
keepResizedFramesbooleanfalseKeep frames a screenshot rendered at another size (Chromium)

See SpeedConfig for the full type definition.


.subtitles(textFn, options?)

Generate subtitles from trace actions using a custom text extraction function.

.subtitles(action => action.docString ?? action.text)
ParameterTypeDescription
textFn(action: TraceAction) => string | undefinedExtracts display text from each action
optionsSubtitleOptionsOptional format settings

.subtitlesFromSrt(srtPath)

Load subtitles from an external SRT file.

.subtitlesFromSrt('./narration.srt')
ParameterTypeDescription
srtPathstringPath to the SRT file

.subtitlesFromTrace(options?)

Auto-generate subtitles from BDD step titles in the parsed trace.

.subtitlesFromTrace()
ParameterTypeDescription
optionsSubtitleOptionsOptional format settings

.textProcessing(config)

Sanitize subtitle text before TTS synthesis. Writes to ttsText field — visual subtitles keep original text.

.textProcessing({ builtins: true })
OptionTypeDefaultDescription
builtinsbooleanfalseEnable built-in sanitization rules
rulesTextProcessingRule[]—Custom regex find/replace rules
transform(text: string) => string—Custom transform function

.autoZoom(config?)

Auto-zoom into user actions detected from the trace.

.autoZoom({ inputLevel: 1.4, clickLevel: 1.5 })
OptionTypeDefaultDescription
clickLevelnumber1.5Zoom level for click actions
inputLevelnumber1.6Zoom level for fill/type actions
idleLevelnumber1.0Zoom during idle (1.0 = none)
centerBiasnumber0.2Blend toward center (0-1)
transitionMsnumber400Transition duration in ms
easingEasingSpec'ease-in-out'Easing function for transitions

.enrichZoomFromReport(steps)

Apply zoom coordinates from external data (e.g., demo report with per-step zoom).

.enrichZoomFromReport([
  { zoom: null },
  { zoom: { x: 0.5, y: 0.8, level: 1.4 } },
])
ParameterTypeDescription
stepsArray<{ zoom?: { x: number; y: number; level: number; hold?: boolean } | null }>Zoom data per step; hold as in zoom()

.direct(provider, options)

Let a director choose camera moves, emphasis and pacing from what appears in the recording. See Visual Direction.

.direct(JevDirector(), { goal: 'Show the report and the final revenue.' })
ParameterTypeDescription
providerDirectorProviderThe director, e.g. JevDirector()
optionsDirectorOptionsgoal (required), observer, sampling and decision budgets, maxZoom, timing, reportPath, onDecision

Requires parse(), may appear once, and cannot be combined with autoZoom() or enrichZoomFromReport().


.cursorOverlay(config?)

Render an animated cursor that moves between action positions.

.cursorOverlay({ size: 24, easing: 'ease-out' })
OptionTypeDefaultDescription
imagestring—Custom cursor image path (PNG)
sizenumber24Cursor size in px (relative to 1080p)
colorstring'#FFFFFF'Dot color (hex)
opacitynumber0.9Opacity 0.0-1.0
easingstring'ease-in-out'Movement easing
moveDurationMsnumber250Maximum travel time to the next pointer position
hideAfterMsnumber500Visible time after reaching a position
shadowbooleantrueDrop shadow on cursor
approachMsnumber500Hold duration for marker-driven clicks (click()) — the cursor glides over the held, painted target
filter(action: TraceAction) => boolean—Filter which actions generate cursor positions
mouseIndicatorboolean | MouseIndicatorConfig—Mouse icon beside the cursor for pressed buttons and wheel turns (details)

.clickEffect(config?)

Add animated ripple effects at click positions with optional sound.

.clickEffect({ color: '#3B82F6', sound: true })
OptionTypeDefaultDescription
colorstring'#3B82F6'Ripple color (hex)
opacitynumber0.5Ripple opacity 0.0-1.0
radiusnumber30Max radius in px (relative to 1080p)
durationnumber400Animation duration in ms
soundstring | true—Click sound path, or true for bundled default
soundVolumenumber0.8Sound volume 0.0-1.0
filter(action: TraceAction) => boolean—Filter which clicks to highlight

.pages(config?)

How pages other than the primary one show when the recording has a video per page. See Multi-Page Recordings.

.pages({ popup: 'overlay', tab: 'replace' })
OptionTypeDefaultDescription
popup'overlay' | 'replace''overlay'Page smaller than the frame: over the darkened page behind, or on a plain background
tab'replace' | 'overlay''replace'Page that fills the frame: hard switch, or shrunk over the darkened page
tabScalenumber0.85Size of an overlaid tab
backdrop{ dim?: number; color?: string }{ dim: 0.6, color: '#000000' }Darkening behind overlays; background behind a replacing popup

.urlBar(config?)

Show the URL of the page on screen as a pill. See URL Bar.

.urlBar({ show: 'host-change', redact: [/acme-\d+/g] })
OptionTypeDefaultDescription
show'host-change' | 'always' | 'marked''host-change'On host changes, always, or at showUrl() markers
durationMsnumber3000Display time in output ms
stripQuerybooleantrueDrop the query string
rewriteArray<{ match: string | RegExp; with: string }>[]Ordered replacements, before redact
redactArray<string | RegExp>[]Parts to mask
redactWithstring'***'Mask text
position'bottom' | 'top''bottom'Edge of the frame
fontFilestringfontconfig defaultFont file for the text
fontSize / color / background / backgroundOpacity28 / '#FFFFFF' / '#1F2328' / 0.8Pill style

.keyOverlay(config?)

Show shortcuts, named keys and modifiers held over mouse actions as a keycap. See Key Overlay.

.keyOverlay({ inputs: ['combos', 'mouse-modifiers'] })
OptionTypeDefaultDescription
inputsKeyOverlayInput[]['combos', 'special', 'mouse-modifiers']Presses that show
labelsRecord<string, string>Ctrl, Esc, ...Labels by key name
separatorstring' + 'Between keys
minShowMsnumber1200Shortest display time in output ms
position'bottom' | 'top''bottom' ('top' with burned-in subtitles)Edge of the frame
fontFilestringfontconfig defaultFont file for the text
fontSize / color / background / backgroundOpacity32 / '#FFFFFF' / '#1F2328' / 0.85Keycap style

.textHighlight(config?)

Render animated marker overlays on text captured by the highlight() helper.

.textHighlight({ color: '#FFEB3B', opacity: 0.35 })
OptionTypeDefaultDescription
colorstring'#FFEB3B'Highlight color (hex)
opacitynumber0.35Highlight opacity 0.0-1.0
durationnumber2000Visibility duration in ms
fadeOutnumber0Fade-out duration in ms
swipeDurationnumber300Swipe-in animation duration in ms
padding{ x?: number; y?: number }—Padding around bounding box in px
filter(highlight: HighlightEvent) => boolean—Filter which highlights to render

.intro(config)

Prepend an intro video with a crossfade transition.

.intro({ path: './assets/intro.mp4', fadeDuration: 500 })
OptionTypeDefaultDescription
pathstringrequiredPath to intro video file
fadeDurationnumber500Crossfade duration in ms

.outro(config)

Append an outro video with a crossfade transition.

.outro({ path: './assets/outro.mp4', fadeDuration: 500 })
OptionTypeDefaultDescription
pathstringrequiredPath to outro video file
fadeDurationnumber500Crossfade duration in ms

.interpolate(config?)

Apply frame interpolation for smoother video output using ffmpeg's minterpolate filter.

.interpolate({ fps: 60, mode: 'blend' })
OptionTypeDefaultDescription
fpsnumber60Target frames per second
mode'dup' | 'blend' | 'mci''mci'Interpolation mode
quality'fast' | 'balanced' | 'quality''balanced'Quality preset
passesnumber1Multi-pass count for smoother results

.backgroundMusic(config)

Add background music with auto-ducking during voiceover.

.backgroundMusic({ path: './assets/music.mp3', volume: 0.3 })
OptionTypeDefaultDescription
pathstringrequiredPath to music audio file
volumenumber0.3Base volume 0.0-1.0
duckingbooleantrueAuto-duck during voiceover
duckLevelnumber0.1Volume during voiceover 0.0-1.0
duckFadeMsnumber500Ducking transition duration in ms
fadeOutMsnumber3000Fade-out at end of video in ms
loopbooleantrueLoop if shorter than video

.voiceover(provider)

Generate TTS audio from subtitle text using a provider.

.voiceover(OpenAIProvider({ voice: 'nova' }))
ParameterTypeDescription
providerTtsProviderA TTS provider instance (OpenAI or ElevenLabs)

.render(config?)

Configure video rendering options.

.render({ format: 'mp4', resolution: '1080p', fps: 60, burnSubtitles: true })
OptionTypeDefaultDescription
format'mp4' | 'webm''mp4'Output format
resolutionstring | { width, height }'1080p'Output resolution
fpsnumber—Output frame rate
burnSubtitlesbooleanfalseBurn subtitles into video
subtitleStyleSubtitleStyle—Subtitle styling options
codecstring—Video codec override
crfnumber—Constant rate factor (quality)

Terminal Operations

Terminal operations execute the pipeline. Nothing runs until one of these is called.

.toFile(outputPath)

Execute the pipeline and write the result to a file.

await pipeline.toFile('demo.mp4')
ParameterTypeDescription
outputPathstringOutput file path

Returns: Promise<void>


.toBuffer()

Execute the pipeline and return the result as a buffer.

const buffer = await pipeline.toBuffer()

Returns: Promise<Buffer>


Inspection Methods

.getStages()

Get the list of stages (for testing/debugging).

Returns: readonly StageDescriptor[]

.getSource()

Get the trace source path.

Returns: string

On this page