Blog
The team5 min read

Crisp browser screen recordings with Playwright (and why recordVideo is blurry)

Playwright's recordVideo makes text soft. We record the Chrome DevTools screencast instead, rebuild a steady 30 fps and encode with x264.

The first web demo we recorded with Playwright looked fine in the thumbnail. Then we played it full screen. Every label was soft at the edges, small text smeared into grey, and a page of numbers looked like it had been photographed through a window.

For a product demo, that's the one thing you can't afford. The viewer has to read the button, the result, the error message. This post is how we fixed it, and the timing bug we found along the way.

Why recordVideo looks soft

Playwright has a built-in option: pass recordVideo when you create the browser context, and you get a WebM file per page. It's convenient, and it's what most guides recommend.

The catch is the codec. Those files are VP8, encoded on the fly at a bit rate meant to keep files small and the test run fast. That's a good trade for its real purpose: watching why a test failed. It's a bad one for a video meant to be read. Sharp edges are exactly what a low bit rate gives up first, and text is nothing but sharp edges.

You can make the viewport bigger, but you're still compressing in real time with settings you don't control. We needed the raw frames.

Record the screencast instead

Chrome can stream what it paints. The DevTools protocol has Page.startScreencast: it sends a JPEG every time the page repaints, each with a timestamp. Playwright gives you a raw DevTools session with context.newCDPSession(page), so you can use it alongside everything else.

Our recorder does three things:

  1. starts the screencast with format: 'jpeg', quality: 92, and a maximum size of 2560 by 1600;
  2. on each Page.screencastFrame, writes the image to disk and keeps its timestamp;
  3. acknowledges the frame with Page.screencastFrameAck, otherwise Chrome stops sending.

The page itself is rendered at a device scale factor of 1.5 on desktop (3 for a phone viewport), so there are more pixels per letter than a plain 1x screen would give.

At quality 92 a JPEG keeps text clean. And since we only encode once, at the end, we choose the settings.

Frames don't arrive at a steady rate

Here's what a screencast is not: a video. Chrome sends a frame when something changes. While the cursor moves, you may get dozens per second. While the page sits still, you get nothing at all for seconds.

A video wants a constant rate. So the frames have to be placed on a timeline, and the gaps filled.

Our first attempt used ffmpeg's concat demuxer: a text file listing each image with its duration, which is the obvious way to say "show this frame for 0.0167 seconds, then that one". It looked right in short clips. On a full demo, the picture drifted away from the voice, by up to two seconds by the end.

The concat demuxer rounds per-image durations, and on such short durations it also replayed the last image. Each rounding is tiny. Over a few thousand frames, it adds up to a video where the voice says "click Check" a long moment after the click happened.

The fix is boring, which is why it works. We build the 30 fps sequence ourselves.

For each output frame k, the time is k / 30. We take the most recent screencast frame captured at or before that time, and create a hard link to it named s000000.jpg, s000001.jpg, and so on. If the page sat still for two seconds, the same JPEG is linked sixty times in a row.

Hard links matter here: they don't copy the image, they add a name to the same file. A three minute recording is 5,400 output frames, but only as many images on disk as Chrome actually sent.

Then a single, plain ffmpeg call reads the numbered sequence at 30 fps and encodes it with x264 at CRF 14, which is close to visually lossless. No durations to round, no drift. Frame 900 is exactly 30 seconds in.

The result is sharp, and the timing holds from the first scene to the last. The final, shareable files are re-encoded later at a sensible size, but they start from a clean master instead of a smeared one.

A cursor people can follow

Headless Chrome has no mouse pointer. Playwright clicks happen, but on video, buttons just change state by themselves. Viewers lose track of what was clicked.

So we inject a cursor. An init script adds a small arrow to every page, fixed on top of everything, ignoring pointer events so it never gets in the way. Before each click, it glides to the target with an easing curve, then a soft ripple marks the click. Its position is kept in session storage, so after a navigation it starts where it left off instead of jumping back to the middle.

We also hide scrollbars in the recording. They add nothing and they flicker when content loads.

What we film this way

Every web demo in Pullscene goes through this recorder. The first real one was Qelka, a phone, email and IP validation API with free tools on its site: seven commits told in 1 min 17. The validation results it shows are dense, small, full of codes and numbers. On the VP8 version you could not read them. On the screencast version you can pause on any frame and read every field.

Recording is only one part of a usable take, though. The gestures have to land, which is why every scene is played once before we film it (Rehearse before you record). And each scene holds until its voice is over, since the voice is generated first (Voice first, picture second).

If you only take one thing

If your Playwright videos look soft and you need people to read them, stop tuning recordVideo. Take the frames from the DevTools screencast, place them on a fixed timeline yourself, and encode once with a codec you control. It's maybe sixty lines of code, and the difference is the difference between a demo and a blur.