Python has two mature ways to drive a real browser and save a screenshot: Playwright and Selenium. This guide gives working code for both, viewport and full page, and the timings we measured when we ran them on the same five pages.
The short version: in Playwright a full-page screenshot is one argument, full_page=True. Selenium has no full-page call for Chrome, but one DevTools Protocol command does the job. Once the browser is running, both take the same time per page. The difference is start-up: Playwright's default headless browser started four to five times faster than Chrome did in our runs, which matters if you launch a fresh browser for every capture. And one Selenium trap cost us a wrong image before we caught it: --window-size sets the window, not the page's viewport.
How we tested
We made a virtual environment and installed playwright 1.64.1, selenium 4.51.0 and Pillow from PyPI, then ran playwright install chromium. Selenium used the Google Chrome already on the machine, 156.0.8078.47. We did not install a driver ourselves: on the first run Selenium Manager, which ships with Selenium, downloaded chromedriver 156.0.8078.47 into ~/.cache/selenium. Its documentation describes exactly this: it detects the installed browser, fetches the matching driver and caches it.
The test pages were example.com, python.org, the Python docs page for pathlib, MDN's HTML reference and playwright.dev's Python home page. Every capture used a 1280 by 800 viewport. All runs were on 24 October 2026 on an Apple M5 Mac on a home connection, so the absolute numbers will differ on your machine; the ratios are the useful part.
Playwright: viewport, full page and one element
from playwright.sync_api import sync_playwright
URL = "https://www.python.org"
with sync_playwright() as p:
browser = p.chromium.launch()
page = browser.new_page(viewport={"width": 1280, "height": 800})
page.goto(URL, wait_until="load")
page.screenshot(path="out/pw-viewport.png")
page.screenshot(path="out/pw-fullpage.png", full_page=True)
page.locator("#touchnav-wrapper header").screenshot(path="out/pw-header.png")
print("Chromium", browser.version)
browser.close()
It printed Chromium 156.0.8078.4 and wrote three files: the viewport at 1280 × 800 (95 KB), the full page at 1280 × 2718 (517 KB) and the header element at 1280 × 587 (106 KB).
A few things worth knowing:
wait_until="load" is already the default for page.goto, according to the API reference. We wrote it out so the wait is visible.
full_page=True captures "a full scrollable page", in the words of Playwright's screenshot guide.
- Leave out
path and page.screenshot() returns the PNG as bytes, which is what you want if the image goes to S3 or a diff tool rather than to disk.
p.chromium.launch() with no channel runs Playwright's "chromium headless shell", a separate build used by default in headless mode. Passing channel="chrome" drives the Google Chrome installed on the machine instead. The docs warn that the two can behave differently.
Selenium: viewport and full page
Selenium's own screenshot call, save_screenshot, captures the current browsing context, which in Chrome means the viewport. The Firefox driver has save_full_page_screenshot, but the Chrome driver has nothing like it; we checked the installed package, and the full-page methods exist only in selenium/webdriver/firefox/webdriver.py. For Chrome, ask the browser directly with the DevTools Protocol command Page.captureScreenshot and its captureBeyondViewport flag, which Selenium's Chrome driver exposes as execute_cdp_cmd.
import base64
from selenium import webdriver
URL = "https://www.python.org"
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--window-size=1280,800")
driver = webdriver.Chrome(options=options) # Selenium Manager finds chromedriver
try:
driver.get(URL)
driver.save_screenshot("out/se-viewport.png")
# Full page: ask Chrome directly through the DevTools Protocol.
shot = driver.execute_cdp_cmd(
"Page.captureScreenshot",
{"format": "png", "captureBeyondViewport": True},
)
with open("out/se-fullpage.png", "wb") as f:
f.write(base64.b64decode(shot["data"]))
size = driver.execute_script("return [innerWidth, innerHeight]")
print("Chrome", driver.capabilities["browserVersion"], "viewport", size)
finally:
driver.quit()
Output:
Chrome 156.0.8078.47 viewport [1280, 657]
The full-page image came out at 1280 × 2718, the same height Playwright produced for the same page. driver.get waits for the page's load event under Selenium's default page load strategy, normal, so the two scripts start capturing at the same point.
But look at the viewport: 657 pixels tall, not 800. The viewport screenshot was 1280 × 657.
The Selenium window-size trap
--window-size=1280,800 sizes the browser window, and the window includes space the page doesn't get. In headless Chrome 156 on our Mac that was 143 pixels of height. With no size set at all, the window was 756 × 556 and the viewport 756 × 413. Calling driver.set_window_size(1280, 800) gave the same 1280 × 657 viewport as the flag.
The fix is to set the viewport, not the window, with the DevTools command Emulation.setDeviceMetricsOverride, which overrides window.innerWidth and window.innerHeight according to the protocol reference:
from selenium import webdriver
def viewport(driver):
return driver.execute_script("return [innerWidth, innerHeight]")
# 1. No window size at all
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
driver.get("https://example.com")
print("default window:", driver.get_window_size(), "viewport:", viewport(driver))
# 2. --window-size sets the window, not the viewport
driver.set_window_size(1280, 800)
print("set_window_size(1280, 800):", "viewport:", viewport(driver))
# 3. Pin the viewport itself through the DevTools Protocol
driver.execute_cdp_cmd(
"Emulation.setDeviceMetricsOverride",
{"width": 1280, "height": 800, "deviceScaleFactor": 1, "mobile": False},
)
print("setDeviceMetricsOverride:", "viewport:", viewport(driver))
driver.save_screenshot("out/se-viewport-fixed.png")
driver.quit()
default window: {'width': 756, 'height': 556} viewport: [756, 413]
set_window_size(1280, 800): viewport: [1280, 657]
setDeviceMetricsOverride: viewport: [1280, 800]
The difference shows. On python.org, the 657-pixel capture ends just under the tagline; the 800-pixel one also shows the notice bar and the top of the next section.

If your screenshots feed a visual regression suite, this matters twice: the image size changes, and so does any layout that depends on viewport height, such as a 100vh hero.
Timing: a fresh browser for every capture
To compare speed fairly, we ran the same job three ways: Playwright with its default headless shell, Playwright driving the installed Chrome (channel="chrome"), and Selenium driving the same Chrome. Each capture started a browser, loaded the page, took a full-page PNG and closed the browser. We did that for all five pages, three rounds, interleaving the tools so that network conditions hit each one equally, and timed each step with time.perf_counter().
| Tool | Start browser | Load page and full-page screenshot | Close | Median total |
|---|
| Playwright, headless shell | 0.08 s | 0.27 s | 0.02 s | 0.37 s |
| Playwright, Chrome | 0.31 s | 0.26 s | 0.06 s | 0.62 s |
| Selenium, Chrome | 0.39 s | 0.26 s | 0.08 s | 0.71 s |
The middle column is the same for all three. Loading a page and capturing it costs what it costs, whichever library sends the commands. The difference is start-up. Playwright's headless shell started in a median 0.08 seconds; full Chrome took about 0.3 seconds under Playwright and 0.39 under Selenium, which also starts a chromedriver process.
Page weight dominated the capture step. The pathlib docs page is long: its full-page PNG was 5.7 to 5.9 MB and took around a second to load and capture with every tool. example.com took about 0.12 seconds.
Timing: one browser, many pages
Most real jobs don't need a fresh browser per page. With one browser kept open and 15 captures (the five pages, three times each) in a single tab, the tools were level:
Playwright (headless shell) 15 captures 5.23 s, median 0.20 s
Playwright (Chrome) 15 captures 4.75 s, median 0.19 s
Selenium (Chrome) 15 captures 4.86 s, median 0.20 s
Opening a new Playwright page for each capture, which isolates each one better, added between 0.02 and 0.06 seconds per capture over our two runs of that variant: 6.07 and 5.49 seconds for the headless shell, 5.33 and 5.29 seconds for Chrome.
So the speed question has a plain answer: reuse the browser, and the library barely matters. If you must start one per capture, for isolation or because each job runs in its own process, Playwright's headless shell saved a quarter to a third of a second each time in our runs.
Capturing several pages at once with async Playwright
Playwright's async API lets one browser load pages in parallel. This script captures the five pages one after another, then all five at once:
import asyncio, time
from playwright.async_api import async_playwright
URLS = [
"https://example.com",
"https://www.python.org",
"https://docs.python.org/3/library/pathlib.html",
"https://developer.mozilla.org/en-US/docs/Web/HTML",
"https://playwright.dev/python/",
]
async def capture(browser, i, url):
page = await browser.new_page(viewport={"width": 1280, "height": 800})
await page.goto(url)
await page.screenshot(path=f"out/async-{i}.png", full_page=True)
await page.close()
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
t = time.perf_counter()
for i, url in enumerate(URLS):
await capture(browser, i, url)
print(f"one after another: {time.perf_counter() - t:.2f} s")
t = time.perf_counter()
await asyncio.gather(*(capture(browser, i, u) for i, u in enumerate(URLS)))
print(f"all five at once: {time.perf_counter() - t:.2f} s")
await browser.close()
asyncio.run(main())
Three runs printed 2.25 and 1.34, 1.99 and 1.42, then 1.98 and 1.25 seconds. Running the pages together saved roughly a third of the time, not four fifths, because the slowest page, the long pathlib docs, sets the floor. With Selenium, parallel captures mean several drivers, each with its own browser, run from threads or processes.
Headless shell or Chrome: are the images the same?
Not quite. We captured playwright.dev's Python page with both Playwright browsers and compared the two full-page PNGs with Pillow. Both were 1280 × 3016 and look identical to the eye. In greyscale, 7.6% of the pixels differed, but only 0.13% by more than 4 levels out of 255, and none by more than 116. That is anti-aliasing and gradient noise, not layout.
It is still enough to fail a strict pixel diff. If you compare screenshots against stored baselines, make both with the same browser build.
Which one to use
| If you need | Use |
|---|
| Full-page screenshots with the least code | Playwright, full_page=True |
| Many short-lived browsers | Playwright's default headless shell |
| Parallel captures from one process | Playwright's async API |
| Screenshots inside an existing Selenium suite | Selenium with Page.captureScreenshot and a pinned viewport |
| No browsers to install or keep updated | A screenshot API |
The last row is the trade our own service makes: the screenshot API runs the browsers so your Python code sends one HTTP request. We didn't include it in these timings.
Whichever library you choose, set the viewport rather than the window, keep one browser alive between captures where you can, and make baseline images with the same browser build you compare them against.