Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reliable Full-Page Screenshot in Headed Chrome (SeleniumBase + Python) #3858

nihar1999 started this conversation in General
Discussion options

Hey,
We’re trying to capture full-page screenshots in headed Chrome (not headless), using SeleniumBase/Selenium with Python in a Robot Framework setup. Here are the few ways that I have tried

  1. CDP-based full-page capture (Page.captureScreenshot)
    Produces accurate full-page screenshots, but becomes unstable under load. We’ve encountered intermittent CDP socket failures and driver crashes on heavier or slower-rendering pages.
with SB(uc=True, headless=False) as sb:
 sb.open(url)
 # Get layout dimensions
 metrics = sb.driver.execute_cdp_cmd("Page.getLayoutMetrics", {})
 width = int(metrics["contentSize"]["width"])
 height = int(metrics["contentSize"]["height"])
 sb.driver.set_window_size(width, height)
 # Take full-page screenshot using CDP
 screenshot_data = sb.driver.execute_cdp_cmd("Page.captureScreenshot", {
 "format": "png",
 "fromSurface": True,
 "captureBeyondViewport": True
 })
  1. Resize + driver.save_screenshot() using scrollHeight/scrollWidth
    This approach works in headless mode only. In headed mode, Chrome silently clips the output to the visible viewport, even after resizing.

  2. Scroll-and-stitch approaches (manual or JS-based)
    These are inconsistent and often fail on complex pages, especially those with sticky headers, floating elements, or dynamically loaded sections. Issues observed include duplicate content, overlapping, or cropped results.

  3. SeleniumBase save_screenshot(..., selector="body")
    This works well in some cases, but on some sites the resulting screenshot is mostly blank or missing content, likely due to the selector not including the visible layout.
    Also, this method uses CDP internally via activate_cdp_mode(), so it may inherit the same CDP stability issues under load.

with SB(uc=True, headless=False, test=True, ad_block=True) as sb:
 sb.activate_cdp_mode(url)
 sb.sleep(2)
 sb.save_screenshot(full_path, selector="body")

Is there a more reliable technique or any enhancement to the above methods that you'd recommend for capturing full-page screenshots in headed Chrome?

You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

See the existing thread here: #3362 (comment).

You must be logged in to vote
1 reply
Comment options

Thanks for the quick reply!
I had gone through that discussion earlier and tried the recommended approaches.

The activate_cdp_mode() method with selector="body" worked on some pages I tested, but results were inconsistent. In certain cases, the screenshot came out incomplete or visually broken, even though the method executed without error. Here’s the code I used to test it on the SeleniumBase homepage:

from seleniumbase import SB
with SB(uc=True, test=True, ad_block=True) as sb:
 url = "https://seleniumbase.io"
 sb.activate_cdp_mode(url)
 sb.save_screenshot("stack.png", selector="body")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /