-
Notifications
You must be signed in to change notification settings - Fork 1.4k
-
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
- 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
})
-
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. -
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. -
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?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment 1 reply
-
See the existing thread here: #3362 (comment).
Beta Was this translation helpful? Give feedback.
All reactions
-
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")
Beta Was this translation helpful? Give feedback.