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

If Selenium reports a 1024×768 Firefox window but the saved PNG is 1024×694, do not assume Selenium ignored your setting. A requested window size, headless Firefox’s virtual display, and the image’s capture scope are different measurements. Set and log the window explicitly, configure the headless display when needed, and inspect the output file itself.

What the different dimensions mean

Three dimensions are commonly confused:

  • WebDriver window size: the width and height returned by driver.get_window_size() after Selenium asks Firefox to resize.
  • Headless virtual display: the no-GUI display used by Firefox. Mozilla documents MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT for this display.
  • Screenshot pixels and scope: the dimensions of the file written by save_screenshot(), which depend on whether you capture the current window or the full document.

These values can differ without indicating a single universal Firefox bug. A 2020 geckodriver report recorded a 1024×768 reported window and a 1024×694 PNG on macOS 10.15.4 with Firefox 78.0.2, geckodriver 0.26.0, Selenium 3.141.0 and Python 3.7. That is one historical reproduction, not a rule that every headless session loses 74 pixels.

Reproduce and measure the mismatch

Use a minimal script and record every relevant version. The log lets you distinguish a resize problem from a screenshot-scope problem.

import platform
import sys
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from PIL import Image

options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)

try:
    print("Python:", sys.version)
    print("OS:", platform.platform())
    print("Firefox:", driver.capabilities.get("browserVersion"))
    print("Geckodriver:", driver.capabilities.get("moz:geckodriverVersion"))

    driver.set_window_size(1024, 768)
    print("Reported size:", driver.get_window_size())
    driver.get("https://example.com")

    output = Path("window.png")
    driver.save_screenshot(str(output))
    print("PNG pixels:", Image.open(output).size)
finally:
    driver.quit()

Install Pillow only for the pixel check (python -m pip install selenium pillow). The browser and driver must already be installed and mutually compatible. The important comparison is the logged size versus the actual PNG dimensions; never infer file dimensions from the WebDriver response.

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.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Set the Selenium window size explicitly

  1. Create Firefox options and enable headless mode.
  2. Start the driver.
  3. Call driver.set_window_size(width, height) before navigation or capture.
  4. Immediately call driver.get_window_size() and log the returned value.
  5. Capture the file and inspect its pixel dimensions independently.

Selenium documents setting and retrieving window dimensions. If the returned value is already wrong, investigate driver or environment behavior before examining page layout. If it is correct but the PNG differs, continue with the display and scope checks below.

Configure Firefox’s headless display

Mozilla documents MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT as controls for the dimensions of Firefox’s no-op virtual display. Set them in the process environment before creating the driver:

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
import os
os.environ["MOZ_HEADLESS_WIDTH"] = "1024"
os.environ["MOZ_HEADLESS_HEIGHT"] = "768"

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(options=options)
driver.set_window_size(1024, 768)
print(driver.get_window_size())
# navigate and capture here
driver.quit()

Keep these variables conceptually separate from Firefox’s command-line screenshot option. Mozilla’s command-line reference documents --window-size width[,height] for use with Firefox’s --screenshot command. That documentation does not establish that every command-line flag is interchangeable with Selenium’s WebDriver sizing API, so use the API and environment variables appropriate to your Selenium setup.

Choose the correct screenshot scope

Current-window capture

The general WebDriver screenshot operation captures the current browser window. Its height can represent the viewport or window area rather than the complete document. Browser chrome is not part of a headless PNG, and layout, device scale and driver implementation can affect the resulting pixel dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
driver.save_screenshot("viewport.png")

Full-document capture

If the requirement is a page-length image, use the Firefox binding’s full-document screenshot method rather than treating a window screenshot as a full-page capture. Selenium’s Python Firefox API provides full-document screenshot methods; check the method available in your installed Selenium version.

# API names vary by Selenium version; inspect the Firefox WebDriver API
# for the full-document method supported by your binding.
driver.get_full_page_screenshot_as_file("page.png")

A full-document image is expected to be taller than the viewport when the page scrolls. Therefore, a height mismatch may be correct behavior when the requested output changed from “visible window” to “entire document.”

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

A diagnostic workflow that isolates the cause

  1. Capture environment details. Record operating system, Firefox, geckodriver, Selenium binding and language versions. Headless behavior is version-sensitive; the historical 1024×694 report cannot be generalized to current releases.
  2. Control the requested size. Set the dimensions with set_window_size(), then print get_window_size().
  3. Control the virtual display. For headless sessions that need it, set MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT before driver startup.
  4. Identify the target scope. Decide whether the deliverable is a current-window image or a full-document image.
  5. Measure the file. Read the PNG, JPEG or WebP dimensions with an image library or an image inspector.
  6. Preserve a minimal reproduction. Keep the URL, script, logs and exact versions if the difference remains. This is essential when reporting a geckodriver issue.

Common symptoms and fixes

Symptom Likely distinction Action
get_window_size() is not the requested value Resize was not applied or the driver adjusted it Set the size after startup, log the returned value, and verify Firefox/geckodriver compatibility.
Window reports 1024×768; PNG is shorter Current-window capture, headless display behavior, or a historical driver issue Set the headless display variables, inspect the file pixels, and test with a minimal reproduction.
Image is much taller than the window Full-document capture Use current-window capture when a viewport image is required.
Image width is correct but page content is clipped Viewport is narrower than the page’s responsive breakpoint Set the intended width before navigation and verify the page’s CSS layout at that width.
Different machines produce different heights OS, browser, driver or Selenium version differences Log all versions and compare the same minimal script across environments.

Reliability and performance considerations

  • Set dimensions before loading the target page so responsive CSS and lazy layout calculations use the intended viewport.
  • Wait for navigation and page content before capture; otherwise a short image can simply be an early document state.
  • Use a deterministic test URL while diagnosing. Dynamic ads, consent dialogs and late-loading fonts can change layout height without changing the browser window.
  • Do not “fix” a 1024×694 output by adding 74 pixels blindly. The historical difference is evidence about one environment, not a conversion constant.
  • Compare lossless PNG dimensions first. JPEG and WebP may be appropriate for delivery, but compression settings do not explain a geometry mismatch.
  • Full-document captures can require substantially more memory than viewport captures on long pages. Limit test pages and capture scope when running many jobs.

Troubleshooting checklist

  • Is --headless enabled only once, through the Firefox options object?
  • Are MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT set before webdriver.Firefox()?
  • Did you log the value returned after set_window_size() rather than only the requested arguments?
  • Did you inspect the actual image file rather than its filename or HTTP metadata?
  • Are you calling a current-window method when you need full-document output, or vice versa?
  • Can you reproduce the result with a fixed URL and the exact Firefox, geckodriver, Selenium and OS versions?
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a website screenshot API and MCP server when you want a rendered image without maintaining a headless Firefox session. A single request returns PNG, JPEG, WebP or PDF; its options include viewport and device presets, full-page capture, lazy-image loading, element selectors, custom CSS and JavaScript, waits, headers, cookies, user agents, geolocation, dark mode and more.

Example using the documented API call (replace the URL and key):

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for parameters and response headers. Before capture it accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. An MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.

The Free plan includes 1,000 shots per month without a card. Paid plans start at $5 for 3,000 shots; yearly billing gives two months free, and every feature is available on every plan. Create a free ScreenshotNeo account.

Python, cURL and Node.js alternatives

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

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(`${res.status} ${res.statusText}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

Frequently asked questions

Does headless Firefox always remove part of the requested height?

No. The 1024×768 versus 1024×694 result comes from one 2020 report. Treat it as a reproduction to investigate, not a universal headless rule.

Which setting controls a Selenium screenshot: --window-size or the environment variables?

They document different interfaces: Selenium’s window API controls the WebDriver window, while Mozilla’s MOZ_HEADLESS_WIDTH and MOZ_HEADLESS_HEIGHT control the headless virtual display. Firefox’s --window-size documentation is specifically associated with the command-line --screenshot command.

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

How can I prove whether a mismatch is caused by the page or the browser?

Capture a fixed, simple page, log the returned window size, and read the image’s pixel dimensions. Then repeat with the same versions and settings on the other machine. This separates page layout changes from browser or driver behavior.

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.