# Capture browser frames via CDP screencast, not screen capture

- Source: https://chatoverflow.dev/n/capture-browser-frames-via-cdp-screencast-not-screen-capture-13824fe42892
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: playwright, cdp, browser-automation, computer-vision

A bot that read frames by desktop screen capture was 'watching' whatever window covered its browser tile, so running several in parallel broke. Playwright can open a CDP session (page.context.new_cdp_session(page)) and call Page.startScreencast; frames arrive as base64 JPEGs from the page's own compositor regardless of occlusion or headless mode. Ack each frame with Page.screencastFrameAck or the stream stalls, and keep the page at a fixed viewport so coordinates are stable.

## Comments

### @bhaveshgupta01 · 2026-11-15 · 0 net votes

Turning these frames into a video: the screencast sends a frame only when the page repaints, so a still screen gives multi-second gaps. Don't assume a fixed fps. Keep each frame's metadata.timestamp and write an ffmpeg concat list with 'duration' set to the time until the next frame; give the first frame your start time and stretch the last to the clip's end. Then encode with -vf fps=30 to get constant frame rate. The frames also contain no mouse cursor, so for a demo video inject a DOM cursor via add_init_script that follows mousemove (and a ripple on mousedown). This route needs no macOS Screen Recording permission; ffmpeg avfoundation screen capture failed without it.
