ScreenshotNeo

BlogHow-to

Selenium Screenshot Crops a Web Page When Browser Window Is Maximized

A maximized Selenium window does not guarantee the saved image has the expected dimensions. Measure the browser window and screenshot separately, then compare configuration and versions.

By the ScreenshotNeo team4 October 20266 min read

Direct answer: maximizing a Selenium browser window does not guarantee that the saved screenshot has the dimensions you expect. Measure the window Selenium reports and inspect the saved PNG’s pixel dimensions separately. If they differ, record the browser, driver, Selenium version, operating system, startup arguments, and whether the browser is headed or headless before changing one setting at a time.

Selenium treats window maximization, explicit window sizing, and screenshot capture as separate operations. On most operating systems, maximizing fills the screen while leaving operating-system menus and toolbars unobstructed; it is not a request for a particular screenshot size. [Selenium WebDriver: windows and frames]

Measure the window and the saved image

Start with a small diagnostic that logs the requested size, the dimensions WebDriver reports, and the PNG dimensions on disk. This example uses Python, Selenium, and Pillow:

from pathlib import Path
from PIL import Image
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

output = Path("selenium-shot.png")
options = Options()
# For a controlled headless test, uncomment and choose an explicit size.
# options.add_argument("--headless=new")
# options.add_argument("--window-size=1800,900")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")

    requested = (1800, 900)
    driver.set_window_size(*requested)
    print("requested:", requested)
    print("reported size:", driver.get_window_size())
    print("reported rect:", driver.get_window_rect())

    driver.save_screenshot(str(output))
    with Image.open(output) as screenshot:
        print("image pixels:", screenshot.size)
finally:
    driver.quit()

Install dependencies with python -m pip install selenium pillow. Selenium’s Python API documents maximize_window(), set_window_size(), get_window_size(), get_window_rect(), and screenshot saving/retrieval. [Selenium Python WebDriver API]

Diagnose the size mismatch step by step

  1. Record the environment. Note OS and version, Selenium version, browser and driver versions, headed or headless mode, and all browser arguments. Keep this with the measured sizes.
  2. Choose one sizing method. For reproducible pixel targets, try set_window_size(width, height). To investigate maximization specifically, call maximize_window() and then query get_window_size() and get_window_rect(). These are distinct measurements and operations. [Selenium window controls]
  3. Inspect the image itself. Read the output PNG dimensions with an image library or image viewer. Do not infer image dimensions from the browser window query.
  4. Compare startup sizing. For Chrome, test its documented start-maximized or window-size startup arguments against runtime maximize or resize calls, changing only one variable per run. ChromeDriver documents these arguments, but does not promise they guarantee a particular screenshot size in every environment. [ChromeDriver capabilities]
  5. Repeat under controlled conditions. Hold versions and execution mode steady while comparing settings. If the discrepancy persists, change a browser, driver, or environment version only when you can record the exact before-and-after configuration.

Why maximizing may not produce the expected capture

The word “maximized” describes a window-management operation, not a target image contract. The resulting dimensions can depend on the environment in which the browser runs, and a successful window-size query alone does not prove that the screenshot has those pixel dimensions.

For example, a SeleniumHQ issue reports that in one Ubuntu 24.04 headless setup using Chrome for Testing and ChromeDriver 130.0.6723.69, the window query returned 1800×900 while the screenshot was reported as 1800×708. This is one reporter’s version-specific observation. The issue does not establish a universal Selenium defect, the underlying cause, or a general fix. [SeleniumHQ issue #14977]

Choose the right kind of screenshot

If the problem is that the image’s viewport is smaller than expected, first make the viewport measurement predictable and verify output pixels. If by “crops” you mean that content below the visible viewport is missing, that is a different requirement: use a full-page capture approach rather than expecting maximize to include the entire document. Selenium’s standard screenshot operation captures the current browsing context; maximizing alone does not mean “capture every page below the fold.”

Likewise, an element screenshot, a viewport screenshot, and a full-page screenshot answer different needs. Confirm which one your workflow requires before tuning dimensions. This article’s diagnostic concerns the reported browser/window versus saved-image dimensions; it does not assume a particular root cause in an unspecified setup.

Common errors and fixes

Symptom Likely diagnostic gap What to do
Window query matches target, PNG is shorter Window dimensions were treated as proof of image dimensions Inspect the PNG’s actual pixel size. Record runtime mode and versions; compare explicit sizing and startup sizing separately.
maximize_window() gives an unexpected size Maximize fills the available screen area, which can differ across desktop, virtual display, or headless configurations Log get_window_size() and get_window_rect(). Try an explicit set_window_size() when a repeatable target is needed.
Startup --window-size appears ignored or differs from runtime size Startup and runtime controls are being mixed or compared without a controlled run Test one method per run and record the exact Chrome arguments. Do not assume the argument guarantees screenshot pixels.
Bottom of a long page is absent A viewport capture was expected to act like a full-page capture Use a full-page capture method appropriate to the browser/tool and verify the resulting dimensions.
Results vary between machines or CI runs OS, browser/driver versions, display setup, or headed/headless mode differs Capture and compare the environment details with each image; reproduce with controlled versions before attributing the cause.
Diagnostic cannot open the image Screenshot may not have been written, may be empty, or may not be a valid PNG Check the boolean result of save_screenshot(), confirm the output path and file size, and inspect the returned bytes or file format.

Performance, reliability, and cost notes

Measuring dimensions adds little work compared with launching a browser and loading a page. For reliable diagnosis, keep page readiness and screenshot timing consistent across runs; otherwise a changing page can make comparisons harder. Save the image and environment metadata together so a later report includes evidence rather than only the requested dimensions.

Browser automation carries setup and runtime costs: browser and driver installation, version coordination, and a browser process for each capture workflow. The research sources do not provide comparable timing, reliability, or cost benchmarks, so there is no source-backed universal performance winner or cost estimate here. Choose based on whether you need browser-level control or a hosted screenshot endpoint.

Or skip the browser setup

If you need a screenshot without maintaining a local browser and driver, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns an image or PDF; its API documentation lists the available parameters and formats.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer())));

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot. Bot checks, blank pages, and failed loads are never billed; response headers report the page verdict and billing status. Its MCP server lets AI agents use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

FAQ

Does maximize mean full-page screenshot?

No. Maximizing changes the window size; it does not by itself request a capture of the entire document.

Should I always use --window-size?

It is a documented ChromeDriver option to compare during diagnosis, but the documentation does not guarantee a specific screenshot size across environments. Measure the resulting image.

Can this issue be diagnosed without my browser and driver versions?

Not to a specific root cause. The title does not identify the environment, and the cited discrepancy is limited to one reported setup. Include exact versions and actual image dimensions when asking for help.

Sources