Skip to main content
Nodriver provides powerful screenshot capabilities for capturing full pages, viewports, and individual elements. This is useful for visual testing, documentation, and debugging.

Page screenshots

Basic screenshot

Capture the current viewport:
From tab.py:1373-1433:

Custom filename

Full page screenshot

Capture the entire page, including content below the fold:
Full page screenshots may take longer for very long pages and consume more memory.

PNG vs JPEG format

Use PNG for screenshots that require transparency or lossless quality. Use JPEG for general purposes to save disk space.

Element screenshots

Capture specific element

Take a screenshot of a single element:
From element.py:843-911:

High-resolution element screenshots

Screenshot multiple elements

Auto-generated filenames

When you use filename="auto" or omit the filename parameter, nodriver generates descriptive filenames:
The filename includes:
  • Hostname from the URL
  • Last part of the path
  • Timestamp (YYYY-MM-DD_HH-MM-SS)
  • File extension

Handling screenshot errors

Screenshots may fail if the page hasn’t finished loading. Always wait for the page to be ready before taking screenshots.

Real-world example from imgur demo

From imgur_upload_image.py:

Screenshot workflow for visual testing

Here’s a complete example for visual regression testing:

Screenshot comparison workflow

Using CDP for advanced screenshots

For more control, use CDP directly:

Best practices