logo of Screenshot for Web
Free toolsPlaygroundDocsBlogPricing
LoginDashboard

Company

HomeFeaturesPricingBlogFacts

Screenshot Tools

Website ScreenshotsFull Page ScreenshotsScrolling ScreenshotsWebsite HistoryPDF Generation APIScreenshot API

Legal

Terms of UsePrivacy PolicyCookie PolicyCopyrightSecurity

Support

FAQSupportContact UsAPI Status
screen shot for web logo

No clutter. No distractions. Just clean, full-page screenshots with smart customization.

© 2026 HYDRANODE LTD. All rights reserved.

Screenshot for Web is operated by HYDRANODE LTD, a company registered in England and Wales, company number 15672526. Registered office: 124 City Road, London, London, England, EC1V 2NX.

FacebookInstagramLinkedInYouTube
  1. Home
  2. Blog
  3. Guides

Website screenshots in Python with Playwright and Selenium, run and timed

Working Python code for viewport and full-page screenshots with Playwright and Selenium, timed on five real pages, plus the Selenium viewport trap we hit.

Screenshot for Web·October 24, 2026·6 min read

Sources

  1. Playwright for Python docs: Screenshots
  2. Playwright for Python docs: Browsers (headless shell and channels)
  3. Playwright for Python API: Page (goto and screenshot)
  4. Selenium docs: Working with windows and tabs (TakeScreenshot)
  5. Selenium docs: Selenium Manager
  6. Selenium docs: Browser options (pageLoadStrategy)
  7. Chrome DevTools Protocol: Page domain (captureScreenshot)
  8. Chrome DevTools Protocol: Emulation domain (setDeviceMetricsOverride)

How this article was made

Researched and drafted with AI assistance from the sources listed. All code was run by us on 24 October 2026 on an Apple M5 Mac (macOS 26.6, Python 3.11.8) with Playwright 1.64.1 and its bundled Chromium 156.0.8078.4, Selenium 4.51.0, and Google Chrome 156.0.8078.47. Every output, image and timing in the article comes from those runs.

Capture any page without ads, banners or chat widgets, free and without an account.

Try the free tools

More articles

  • News

    Puppeteer 25.19 stops print and dark mode emulation from cancelling each other

    Before Puppeteer 25.19.0, emulateMediaType and emulateMediaFeatures reset each other, losing print or dark mode. Our tests, the fix and a workaround.

    November 26, 2026
  • News

    Chrome 158 drops XSLT: what it does to screenshots of sitemaps and feeds

    We captured eight live sitemaps in Chrome 156 and Chromium 158. Styled pages turn into raw XML, a red warning bar is already in captures, and two fixes work.

    November 9, 2026
  • Research

    Chrome DevTools' full-size screenshot: where it fails on long and lazy pages

    We ran DevTools' full-size screenshot on six long pages: it stops at 16,384 pixels and misses content that appears on scroll. Here's why, and the fixes that worked.

    November 8, 2026

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.

Two Selenium captures of python.org side by side. Left, made with --window-size=1280,800: the image is 1280 by 657 and ends under the "Learn More" link. Right, made with setDeviceMetricsOverride: 1280 by 800, also showing a yellow notice bar and the top of the next row.

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().

ToolStart browserLoad page and full-page screenshotCloseMedian total
Playwright, headless shell0.08 s0.27 s0.02 s0.37 s
Playwright, Chrome0.31 s0.26 s0.06 s0.62 s
Selenium, Chrome0.39 s0.26 s0.08 s0.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 needUse
Full-page screenshots with the least codePlaywright, full_page=True
Many short-lived browsersPlaywright's default headless shell
Parallel captures from one processPlaywright's async API
Screenshots inside an existing Selenium suiteSelenium with Page.captureScreenshot and a pinned viewport
No browsers to install or keep updatedA 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.