Flow capture
This skill covers the mechanics: how to record, how to render, and how to make a recording good. When a recording counts as proof, and how to label mockups, is up to the skill that uses it (flow-proof, flow-mockup, or a project skill).
Files:
capture.ts: the Playwright helper. Copy it into the project's e2e folder.stitch.py: the renderer. Run it withuv run, which brings its own Pillow. It also needsffmpeg.
Requires Playwright 1.59 or later, for page.screencast, and Chromium.
Record
import { createFlowCapture, FLOW_CAPTURE_CONTEXT_OPTIONS, FLOW_CAPTURE_TEST_OPTIONS } from './capture';
test.skip(!process.env.FLOW_OUT, 'Set FLOW_OUT to record this flow');
test.use(FLOW_CAPTURE_TEST_OPTIONS);
test('invite a teammate', async ({ browser }) => {
const context = await browser.newContext({ storageState, ...FLOW_CAPTURE_CONTEXT_OPTIONS });
const page = await context.newPage();
const flow = await createFlowCapture(page, { outDir: process.env.FLOW_OUT, title: 'Invite a teammate' });
await page.goto('/team');
await flow.verify('Team page', () => expect(page.getByRole('table')).toBeVisible());
await flow.click('Open the invite dialog', page.getByRole('button', { name: 'Invite' }));
await flow.type('Enter their email', page.getByLabel('Email'), '[email protected]');
await flow.press('Send with Enter', 'Enter');
await flow.verify('Sam is listed as invited', () => expect(page.getByText('[email protected]')).toBeVisible(), page.getByRole('table'));
await flow.finish();
await context.close();
});
| Method | Records | Shown as |
|---|---|---|
click(label, target, perform?) | a click; pass perform for a custom click, such as a retry | the cursor travels, presses, and a ripple spreads |
hover(label, target) | a hover | the cursor travels; no ripple |
type(label, target, text) | a click, then typing at 35 ms per key | a click, then the text appearing at real speed |
press(label, key) | a keyboard press | no cursor motion; the camera stays put |
scrollTo(label, target) | a smooth scroll | the real scroll, in overview |
act(label, action, target?) | anything else | the cursor travels if there is a target; no click is drawn |
shot(label, target?) | a still | a hold, focused on the target if given |
verify(label, assertion, target?) | runs the assertion, then a still | a hold, with a check mark in the caption |
The recording saves:
- a 2× screencast of the whole run, as JPEG frames with timestamps
- for each step: its kind, the target's position, the start and end times of the action, and before/after screenshots
- provenance: time, origin, browser version, and for the directory the spec runs from, the git branch (or "detached"), commit, whether there are uncommitted changes, and the number of untracked files
- every document, fetch or XHR response that no server answered, meaning it was fulfilled by
page.routeor came from cache. WebSockets, EventSource, scripts and images aren't checked.
Each capture first deletes what an earlier capture left in the same folder (frames/, video/, manifest.json, summary.md, and the flow-* and compare-* videos and GIFs), and writes the manifest only once the flow passes. A failed run therefore leaves nothing a renderer could pass off as a result.
Render
uv run stitch.py <capture> [--mode video|slides] [--compare <capture> --labels Before,After] [--motion subtle|full|none]
[--zoom X] [--badge TEXT] [--no-header] [--no-captions] [--no-cursor] [--theme teal|blue|dark|light] [--bg <image>]
[--width N] [--fps 30] [--gif] [--preview] [--out <file>]
--mode video(the default when frames exist) writesflow-video.mp4: the real recording from the first step to the last, retimed. Page loads before the first step aren't shown, so start with averifyorshot.- Each action plays at real speed for its first 1.2 s; typing plays in full, up to 4 s. Everything after that plays at 6×.
- Stretches with no repaint longer than 0.2 s shrink to 0.08 s. Waits mostly disappear, but nothing is reordered or cut.
- While sped up, each output frame averages up to 12 of the source frames it covers, so a state that flashed for 50 ms still shows as a faint flash. A small "Sped up" tag shows under the pane.
--mode slideswritesflow-slides.mp4: crossfades between screenshots. The header always says "Stitched from screenshots", and--no-headerdoesn't remove it.--compare DIRwritescompare-<mode>.mp4: two captures of the same spec side by side. On the faster side, both the wait before each step and the step itself are padded, so both panes start and finish every step together. Each pane has its own caption and its own commit, and the renderer prints a note when the steps' labels differ.--badge TEXTpins a label in the header, for exampleMockup.--previewrenders at 960 px and 24 fps without motion blur, for quick checks.--gifalso writes a GIF, shrinking the width until it fits GitHub's 10 MB limit.summary.mdlists each step with its final screenshot, marks verified steps with ✓, and lists any responses no server answered.
Motion
The defaults follow one rule: motion exists only to show where to look or what happened, and should never pull attention from the app.
| Motion | Purpose | Behaviour |
|---|---|---|
Camera (subtle, the default) | Show where the action is | Zooms 1.5× on small targets. It stays still while the next target is already well inside the view, so a menu sequence doesn't make it hop. Zooming in is deliberate and pulling back is quicker. There is no overshoot. |
Camera (full) | Tutorials | Zooms 1.8× and re-centres on every target |
Camera (none) | Reduced motion | Never moves; the cursor and captions still show |
| Cursor | Show what was acted on | Travels along a slight curve. The approach takes 0.45–0.9 s depending on distance (plus 0.25 s on long pans), and the cursor arrives with a quarter of it to spare. It is hidden until the first pointer action or targeted still, and while scrolling. |
| Press and ripple | Confirm a real click | 90 ms dip to 0.88×, 160 ms release, one ring, no bounce. Only click and type get one. |
| Caption | Say what's happening | Fades out in 120 ms and the next one rises in over 220 ms, both ease-out |
| Intro | Start the video | The frame fades in from 0.97× over 400 ms, ease-out |
| Motion blur | Hide stepping on fast moves | Only on frames that move more than 6 px |
| Long pans | Keep the viewer oriented | Pans longer than 40% of the screen pull back to an overview mid-flight |
| Page change | Show the new page | The camera pulls back after an action that changes the URL path; query-string changes such as filters don't count |
Recording rules
These make a recording worth watching, and keep it truthful whoever ends up using it.
- One flow, one story: 4–12 steps, and under about 30 s once rendered. Split anything longer.
- Start on a settled page. The first step is a
verifyorshotafter the page loads. - Labels say what the user does, in under 6 words ("Open the filter menu"). Labels for result steps state the outcome ("Only archived projects remain").
- Back every claim with a
verify. If a caption claims a result, it comes from averifywhose assertion passed. A failed assertion fails the test, so no video exists that claims something false. - Act through locators, the way a user would. Don't change the page with
page.evaluate,dispatchEventorelement.click()in the page context, because the video would show a result with no visible cause. - Make typing visible. Use
flow.type, notfill. - Leave pacing to the renderer. Don't add
waitForTimeoutto slow the video down; the retimer controls pacing. - Keep one viewport. Use the 1440×900 @2× from
FLOW_CAPTURE_CONTEXT_OPTIONSand don't resize mid-flow. Build the context frombrowser, because fixtures that create their own context drop these options. - Keep tracing off.
FLOW_CAPTURE_TEST_OPTIONSturns it off: tracing runs its own 800 px screencast, and the recording would share it. - Use test data only. Never record real people's data, secrets or tokens. Typed text and URLs end up in the video.
- Make transient states visible honestly. To show a loading state, hold the real response with
page.route(..., route => route.continue())after a short pause, notfulfill. That way the response still comes from the server. - Watch it before sharing. Render with
--preview, look at it, then do the full render.
Limits:
- Only the page passed to
createFlowCaptureis recorded. A new tab needs its own capture. - Dev-only overlays from Next.js are hidden. Other frameworks' overlays may need their own CSS.