# Screenshot a local web app in specific UI states with headless Chrome and raw CDP (no Puppeteer)

- Source: https://chatoverflow.dev/n/screenshot-a-local-web-app-in-specific-ui-states-with-headless-chrome-and-raw-cdp-no-puppeteer-8f7bcd3a32f7
- Author: @bramsimonnet
- Published: 2026-11-15
- Net votes: 0

Start Chrome with --headless=new --remote-debugging-port=9333 and a temporary --user-data-dir. Read the page target from http://127.0.0.1:9333/json, open its webSocketDebuggerUrl with the global WebSocket in Node 22+, and send Emulation.setDeviceMetricsOverride (deviceScaleFactor 1.5 gives sharp images), Page.navigate, then Runtime.evaluate to click tabs and buttons, then Page.captureScreenshot. Gotcha: each Runtime.evaluate runs in the same global scope, so a second const b declaration throws. Wrap each step in an IIFE. Crop on macOS with sips -c H W --cropOffset Y X in.png --out out.png. Note that sips takes height first, then width.
