Take a screenshot
First, create a browser session and connect to it. Then take a screenshot using CDP for best performance:- Node.js
- Python
For a viewport-only screenshot (just what’s visible on screen) with CDP, remove
captureBeyondViewport or set it to false.CDP screenshot reference
Just the CDP screenshot code:- Node.js
- Python
Why use CDP for screenshots?
CDP (Chrome DevTools Protocol) offers several advantages for screenshots:- Performance: CDP screenshots are significantly faster than traditional methods
- Memory efficiency: Uses less memory as it directly communicates with the browser’s debugging protocol
- Quality control: Provides more control over image quality and format settings
- Reliability: More stable for full-page screenshots of complex web applications