Use Firefox’s headless WebDriver, navigate to the page, wait until its useful content is rendered, then call save_screenshot(). That method writes the current viewport as a PNG. For the entire document, Firefox’s Selenium driver provides save_full_page_screenshot(). If you need image data in your Python process instead of a file, use get_screenshot_as_png() or get_screenshot_as_base64().
Prerequisites and installation
Install Firefox, Python 3, and Selenium. The Selenium package must be able to start a compatible Firefox WebDriver (Selenium Manager can usually obtain the driver automatically in current Selenium releases).
python -m pip install -U selenium
Headless mode is selected while creating webdriver.Firefox; screenshot methods are called only after navigation. Always close the browser in a finally block so the Firefox process is released even when capture or file writing fails.
Capture the current Firefox viewport
save_screenshot(path) captures what is visible in the current browser window and writes a PNG file. Give it an absolute path ending in .png, create the destination directory first, and check its Boolean result.
#1 Best Overall
- 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.
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
output = Path("/tmp/selenium-shots")
output.mkdir(parents=True, exist_ok=True)
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
try:
driver.set_window_size(1440, 900)
driver.get("https://example.com")
ok = driver.save_screenshot(str(output / "example-viewport.png"))
if not ok:
raise OSError("Selenium could not write the viewport screenshot")
finally:
driver.quit()
The image dimensions depend on the browser window. Set the size deliberately when screenshots are used in visual tests, documentation, or generated previews.
Capture the entire page in Firefox
Firefox exposes a full-document method that includes content below the viewport. It still writes a PNG and still requires a full path.
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
path = Path("/tmp/selenium-shots/example-full-page.png")
path.parent.mkdir(parents=True, exist_ok=True)
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
try:
driver.get("https://example.com")
ok = driver.save_full_page_screenshot(str(path))
if not ok:
raise OSError("Selenium could not write the full-page screenshot")
finally:
driver.quit()
save_full_page_screenshot() is Firefox-specific. The Firefox API also exposes get_full_page_screenshot_as_file() for a file-oriented full-document capture. Use the method available in the Selenium version installed in your environment.
Choose the right screenshot output
| Need | Method | Result | Important detail |
|---|---|---|---|
| Visible browser area | save_screenshot(path) |
PNG file | Uses the current window dimensions |
| Entire Firefox document | save_full_page_screenshot(path) |
Full-document PNG file | Firefox capability; requires a .png path |
| Image processing in Python | get_screenshot_as_png() |
PNG bytes | No intermediate file |
| Text-safe transport | get_screenshot_as_base64() |
Base64 string | Decode it before treating it as image bytes |
Save PNG bytes or base64 without a temporary file
Use the in-memory methods when a web service, test, object store, or image library will consume the result directly.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Rank #2
- 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.
from base64 import b64decode
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("-headless")
driver = webdriver.Firefox(options=options)
try:
driver.get("https://example.com")
png_bytes = driver.get_screenshot_as_png()
Path("/tmp/viewport-from-bytes.png").write_bytes(png_bytes)
encoded = driver.get_screenshot_as_base64()
Path("/tmp/viewport-from-base64.png").write_bytes(b64decode(encoded))
finally:
driver.quit()
Firefox also provides full-page PNG and base64 variants in its API. Select the variant that matches your downstream interface rather than writing and rereading a file.
Make the captured state reproducible
Wait for meaningful content
A screenshot records the rendering state at the instant the command runs. A successful driver.get() does not guarantee that client-side content, images, or fonts have finished. Use an explicit wait for a page-specific element instead of relying on an arbitrary long sleep.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
# after driver.get(...)
WebDriverWait(driver, 20).until(
lambda d: d.find_element(By.CSS_SELECTOR, "main").is_displayed()
)
Choose a selector that represents usable content on your site. For pages that load additional content after the first render, wait for that content or for a known loading indicator to disappear before capturing.
Control the viewport
Call set_window_size(width, height) (or set_window_rect) before navigation when exact viewport dimensions matter. A full-page capture still uses the page’s document dimensions, while a normal capture is limited to this window.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallRank #3
- 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.
Keep browser lifetime bounded
Use a navigation timeout appropriate to your pages and always call quit(). For batch jobs, reuse one driver for several URLs when isolation is not required; starting a new Firefox process for every image adds startup cost.
Why Selenium returns False when saving
The file-oriented screenshot methods return False on an I/O error rather than silently claiming success. Typical causes and fixes are:
- Directory does not exist: create it with
Path(path).parent.mkdir(parents=True, exist_ok=True). - Relative or malformed path: pass a full, absolute path and use the
.pngextension required by the Firefox methods. - No write permission: select a directory writable by the account running the process; containerized jobs often need a mounted writable directory.
- Path points to a directory: provide a filename, not only a folder.
- Storage is full: check available disk space and clean old captures.
- Browser process ended early: inspect the preceding navigation or WebDriver exception and ensure the driver remains alive until the save call completes.
Do not ignore the Boolean result. Raise an exception or otherwise mark the job failed so a missing image cannot be mistaken for a valid capture.
Troubleshoot blank, partial, or unexpected images
The image is blank or shows a loading shell
Capture later: wait for a meaningful selector, dismiss an application’s own loading state when appropriate, and verify that the URL is reachable from the machine running Firefox. A headless browser still receives the same network failures, authentication requirements, and bot challenges as a normal browser.
Recommended Free Tools
Rank #4
- 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
Only the top portion appears
Use save_full_page_screenshot() instead of save_screenshot(). If the site uses an internal scroll container, a full-document capture may not include content hidden inside that container; scroll or capture the element according to the application’s layout.
Images or lazy content are missing
Wait for the relevant elements, scroll through lazy-loaded sections when necessary, and capture only after their source images have loaded. The screenshot API does not retroactively wait for resources.
Results differ between runs
Fix the window size, use a consistent Firefox version and viewport, wait on deterministic selectors, and control data that changes between requests. Animations, rotating banners, current timestamps, and personalized content can legitimately change pixels.
Full-page capture is unavailable
Confirm that the session is Firefox and that your Selenium version includes the Firefox full-page method. The ordinary WebDriver screenshot method is portable, but full-document capture is a Firefox capability.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Performance, reliability, and cost considerations
- Startup: Firefox startup is usually more expensive than taking another image with an already-running driver, so reuse a session for trusted batches.
- Memory: full-page PNGs can be large for long documents. Write or stream bytes promptly and avoid retaining many images in memory.
- Determinism: fixed dimensions and explicit waits improve visual-test repeatability more than simply increasing a global sleep.
- Failure handling: record the URL, exception, and output path; retry navigation failures separately from file-system failures.
- Security: treat captured pages and custom headers or cookies as sensitive. Do not log credentials or publish screenshots containing private data.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. One GET request returns PNG, JPEG, WebP, or PDF, so you do not have to install or operate Firefox for a straightforward capture. Its cleanup steps accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before the shot; each step can be disabled.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Python:
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)
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}`);
See the ScreenshotNeo documentation for parameters. It supports full-page capture with lazy images, CSS-selector element capture, dark mode, 12 device presets and custom viewports, retina scale, PDF paper size/margins/landscape/page ranges, HTML/CSS rendering, custom JavaScript and CSS, pre-capture clicks, hidden selectors, waits for selectors/delay/network idle, blocking ads/trackers/requests/resource types, custom headers/cookies/user agents/Authorization, timezone and geolocation, transparent backgrounds, resizing, selectable-TTL caching, signed image links, asynchronous jobs with signed webhooks, up to 100 URLs per bulk call, a usage API, an OpenAPI specification, and familiar parameter names for easier migration.
Best Value
- 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.
Only clean shots are billed. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response reports the result with X-Page-Verdict and X-Billed headers. An MCP server supplies take_screenshot, get_page_info, and capture_pdf tools 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. Create a free ScreenshotNeo account.
Quick decision checklist
- Need exactly what a user sees in a controlled Firefox window? Use
save_screenshot(). - Need everything in the Firefox document? Use
save_full_page_screenshot(). - Need to pass the image to Python code? Use PNG bytes or base64.
- Need repeatable output? Set the window size and wait for a meaningful element.
- Need a managed API, PDF output, cleanup, or AI-agent access? Use ScreenshotNeo instead of maintaining a browser.
Frequently Asked Questions
Does headless Firefox change Selenium’s screenshot methods?
No. Add the -headless argument when creating Firefox; call the same screenshot methods after navigation and readiness waits.
Can I save a Selenium screenshot as JPEG?
The Firefox Selenium methods described here write PNG files or return PNG data. Convert the PNG afterward with an image-processing library if another format is required.
Should I use a fixed sleep before every screenshot?
No. An explicit wait for page-specific content is generally more reliable than a fixed delay, because it finishes when the required state exists.
Quick Recap
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.

