Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Fix Selenium Screenshots with the Wrong Size in Headless Chrome

A wrong-size headless Chrome screenshot can come from window sizing, viewport dimensions, or device scaling. Measure each value and troubleshoot the mismatch systematically.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set the requested dimensions, then verify what Chrome actually used. A Selenium screenshot’s size can differ because the browser window was not resized, the page’s CSS viewport differs from the outer window, or device scaling changes the image’s pixel dimensions. Check all three before changing settings.

Measure the window, viewport, and screenshot separately

Do not assume that --window-size alone proves the screenshot will have those pixel dimensions. Record these values after Chrome starts:

As an Amazon Associate I earn from qualifying purchases.

  • WebDriver window size: the dimensions Selenium reports for the browser window.
  • Page viewport: window.innerWidth and window.innerHeight, which describe the page’s CSS viewport.
  • Raster size: the actual width and height of the saved PNG or other image file.

Also log window.devicePixelRatio and window.screen.width/height. They help distinguish a viewport mismatch from device-scale or emulation effects. Chrome DevTools documents device metrics overrides that can affect page-visible screen and viewport values as well as device scale factor: Chrome DevTools Protocol: Emulation.setDeviceMetricsOverride.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set and verify the headless Chrome window size

  1. Pass an explicit size when creating the Chrome session. ChromeDriver’s options documentation demonstrates the window-size=1000,800 argument form: ChromeDriver capabilities.
  2. Read the size after startup. Use Selenium’s window-management API to inspect or set the window dimensions: Selenium WebDriver drivers and window management.
  3. Compare the page metrics with the file’s pixel dimensions. If the window value is wrong, investigate whether the option reached Chrome and whether the driver applied it. If the CSS viewport is wrong, adjust the effective window or deliberately use device emulation. If the CSS values match but the image pixels do not, investigate scaling.

Runnable Python diagnostic

This diagnostic sets a requested window size, prints the observed window and page metrics, and saves a screenshot. It is a documented-API pattern, not a guarantee that every operating system or runtime will produce identical image dimensions.

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--window-size=1440,900")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    print("webdriver window:", driver.get_window_size())
    print("page metrics:", driver.execute_script("""
        return {
          innerWidth: window.innerWidth,
          innerHeight: window.innerHeight,
          screenWidth: window.screen.width,
          screenHeight: window.screen.height,
          devicePixelRatio: window.devicePixelRatio
        }
    """))
    driver.save_screenshot("page.png")
finally:
    driver.quit()

Inspect page.png with an image viewer or image-metadata tool and compare its pixel width and height with the printed values. Selenium documents both reading window dimensions and taking screenshots of the current browsing context: Selenium WebDriver documentation.

Choose desktop sizing or device emulation intentionally

For an ordinary desktop viewport

Start with the explicit Chrome window argument and Selenium’s window-management API. Verify the observed window and page values rather than treating the configured value as proof of the effective viewport.

For a simulated device viewport

Use Chrome DevTools Protocol device metrics when you specifically need to emulate a device. Emulation.setDeviceMetricsOverride can override width, height, device scale factor, screen dimensions, and mobile emulation. Some protocol parameters are marked experimental; use the protocol supported by the Chrome version you run. This is a different control from resizing an ordinary desktop browser window.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check headless mode and browser-driver versions

Chrome’s headless documentation shows --headless=new for Selenium and a command-line example combining --screenshot with --window-size: Chrome Headless mode. The documentation introduces new Headless in Chrome 112 and explains that it creates, but does not display, platform windows.

Selenium’s Chrome-specific guidance says the Chrome browser and ChromeDriver versions should match at the major-version level: Selenium on Chrome. Check the actual Chrome, ChromeDriver, Selenium, and operating-system versions when diagnosing a mismatch.

User-submitted reports illustrate why version and platform details matter, but do not establish a universal current bug. A 2023 report concerned Chrome/ChromeDriver 110 and a requested 1920×1080 size; a 2025 report described Linux, Chrome 137.0.7151.68-1, Selenium 4.33, and a reported window around 800×600: 2023 Selenium issue and 2025 Selenium issue. Treat these as clues for matching your environment, not evidence that current headless Chrome always ignores the size flag.

Wait for the page state you intend to capture

Screenshot timing can affect what content appears, but waiting does not itself change the viewport dimensions. In Selenium, wait for the page state your test needs—such as a specific element becoming visible—before calling save_screenshot. For Chrome’s command-line screenshot option, the headless documentation describes capture after page load and options involving a timeout or virtual-time budget.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot by comparing observed values

  • get_window_size() is not the requested size: confirm that the Chrome option was added to the options object passed to the driver, inspect session startup and driver behavior, then check browser and driver versions.
  • Window size looks right but innerWidth/innerHeight do not: the page’s effective viewport is not the same as the reported outer window dimensions. Check the effective window configuration and whether device metrics or mobile emulation are active.
  • CSS viewport values match but the image pixel dimensions differ: inspect devicePixelRatio, device-scale-factor overrides, and any image scaling in the capture path.
  • The image has the right dimensions but the wrong content: wait for the relevant page state before capturing; investigate loading or navigation timing separately from sizing.
  • The mismatch appears only on a particular runtime: record Chrome, ChromeDriver, Selenium, operating system, requested dimensions, all observed metrics, and saved image dimensions. Compare like-for-like before concluding that a flag is ignored.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a clean website capture rather than a Selenium browser session, ScreenshotNeo returns an image or PDF from one GET request. Its API supports PNG, JPEG, or WebP output and PDF capture. The cookie-banner, popup, and chat-widget cleanup can be turned off step by step; the service says bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. It also offers an MCP server with screenshot, page-info, and PDF tools for AI agents. Plans include 1,000 shots per month free with no card; paid plans start at $5 for 3,000 shots. See the ScreenshotNeo API documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

Sign up for 1,000 free screenshots a month with no card.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.