ScreenshotNeo

BlogHow-to

How to Capture a Webpage Screenshot with Selenium Using a Proxy

Configure a browser proxy in Selenium, capture a webpage screenshot, handle full-page needs, and troubleshoot proxy and file errors.

By the ScreenshotNeo team4 October 20267 min read

To capture a webpage screenshot with Selenium through a proxy, configure the proxy on the browser options, open the target URL, and save the browser window as a PNG. In Python with Chrome, the basic flow is:

  1. Set a manual proxy on ChromeOptions.
  2. Create the WebDriver session with those options.
  3. Navigate to the page and call save_screenshot.
  4. Check the return value and always close the browser.

This captures the current browser window. A full-document screenshot is a different operation and browser support varies. The examples below use a placeholder proxy endpoint; replace it with an endpoint and protocol supported by your proxy provider and browser.

1. Configure Selenium’s browser proxy

When the page visit itself must use a proxy, configure the browser session. Selenium’s driver-options documentation shows a manual proxy set on browser options. Selenium Manager also has a proxy setting, but that setting applies to Selenium Manager’s own network access for browser and driver management; it does not replace the browser page-traffic proxy.

Python with Chrome

from pathlib import Path

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

proxy_address = "proxy.example:8080"  # Replace with your authorized proxy host and port.
output_path = Path("screenshot.png").resolve()

options = webdriver.ChromeOptions()
options.proxy = Proxy({
    "proxyType": ProxyType.MANUAL,
    "httpProxy": proxy_address,
    "sslProxy": proxy_address,
})

# For a headless environment, uncomment the next line:
# options.add_argument("--headless")

# Selenium Manager can provision a driver where supported and configured.
driver = webdriver.Chrome(options=options)
try:
    driver.set_window_size(1440, 1000)
    driver.get("https://example.com")
    saved = driver.save_screenshot(str(output_path))
    if not saved:
        raise OSError(f"Selenium could not save screenshot to {output_path}")
    print(f"Saved {output_path}")
finally:
    driver.quit()

The example sets both httpProxy and sslProxy to the same endpoint for a common HTTP and HTTPS proxy arrangement. Proxy protocols and accepted capabilities differ. Confirm the expected scheme and browser configuration with the provider; do not assume every HTTP proxy, SOCKS proxy, or authenticated endpoint uses the same fields.

Proxy credentials

Do not put real credentials in source code, screenshots, logs, or a committed configuration file. Authentication support depends on browser, proxy protocol, and authentication method. The documented options pattern above does not establish a universal way to pass username and password. Follow the proxy provider’s browser-specific instructions or use an authentication method supported by that browser and endpoint. Keep secrets in an approved secret store or environment configuration, and avoid logging credential-bearing proxy URLs.

Selenium Manager’s separate proxy setting

If Selenium Manager needs network access through a proxy to obtain a browser or driver, its documentation describes a separate proxy configuration, including --proxy, a proxy configuration key, and SE_PROXY. Configure that only for Manager’s own network connection. For the actual page request, configure browser options as shown above. Check the current Selenium Manager documentation for the exact form supported by your installed Selenium version.

2. Save the screenshot and choose the right output

Selenium’s Python WebDriver API documents save_screenshot(filename) as saving the current window to a PNG image file. It also provides file and in-memory forms:

  • save_screenshot(path) saves a PNG and returns whether saving succeeded.
  • get_screenshot_as_file(path) saves to a file and documents a boolean result, including False on an I/O error.
  • get_screenshot_as_png() returns PNG bytes for further processing or upload.
  • get_screenshot_as_base64() returns Base64 data for embedding in HTML or passing to a consumer that expects it.

Use an absolute path or a known writable working directory in scheduled jobs and containers. A screenshot call can succeed while showing an error page, a proxy login page, or an incompletely loaded target; inspect the captured image when correctness matters.

Window screenshot or full-page screenshot?

The standard call captures the current browser window, so content below the viewport is not necessarily included. Set the window size before navigation or capture if a particular viewport is required. Resizing the window does not guarantee capture of the entire document.

Selenium’s Python Firefox API documents full-document methods such as get_full_page_screenshot_as_file(filename) and save_full_page_screenshot(filename), along with byte and Base64 variants. Those cited methods are Firefox-specific; do not assume they are available through every browser driver. For Chrome or another browser, verify the current browser-specific Selenium API before relying on a full-page method. If the target requires scrolling to trigger lazy-loaded content, scrolling and waiting may be necessary even when using a full-document capture facility.

3. Diagnose proxy and screenshot problems

  1. Start without the proxy. Confirm that the driver starts and can load a known page. This separates driver installation and browser startup problems from proxy connectivity.
  2. Enable the browser proxy. Visit a page you are authorized to access. Confirm the browser reaches the expected content, rather than a proxy error or authentication page.
  3. Check the proxy path. If appropriate, use a trusted endpoint to inspect apparent egress. This is a diagnostic check, not a Selenium feature; follow the endpoint’s terms and avoid sending sensitive data.
  4. Check the output path. Use a writable absolute path, check the screenshot method’s boolean result, and verify that the process user can write to the destination directory.
  5. Check what the image contains. Decide whether a viewport image is enough. If you need the full document, use a method documented for your selected browser.
Symptom Likely cause What to check or change
Browser starts but the page cannot load Wrong proxy host or port, unsupported protocol, unreachable endpoint, or proxy authentication issue Check the endpoint details and protocol with the provider. Test the browser without the proxy, then isolate proxy connectivity and authentication.
Page loads directly instead of through the proxy Proxy configured for Selenium Manager rather than the browser session, or browser capability not accepted Set the proxy on the browser options used to create the WebDriver. Confirm the browser’s effective network route with an appropriate trusted diagnostic.
Screenshot file is missing or empty Path is unwritable, directory does not exist, or save returned failure Use a known writable absolute path, create the directory first if needed, check the boolean return, and inspect process permissions.
Only the visible area appears The standard screenshot method captures the current window Use a full-document method documented for the chosen browser. The cited Selenium full-page methods are for Firefox’s Python driver.
Screenshot shows a loading state or partial content Capture happened before the page finished rendering or delayed content appeared Wait for a meaningful page condition before capturing. For lazy-loaded content, scroll as needed and wait for the relevant elements.
Proxy credentials appear in logs Credential-bearing values were printed or included in exception output Remove secrets from logs and source control, rotate exposed credentials, and use secret storage plus redacted diagnostics.

4. Performance, reliability, and cost considerations

Each capture starts with browser and driver setup, then page navigation and rendering; the proxy adds a network hop. Reuse a browser session for multiple authorized captures when isolation requirements allow, and close it reliably when work finishes. Set sensible waits around page conditions rather than taking the screenshot immediately after navigation if the page renders asynchronously.

For repeatable output, set the viewport explicitly, use a stable destination path, record the target URL and capture time without recording secrets, and check both navigation outcome and file-save result. Proxy availability, authentication, destination access, browser behavior, and filesystem permissions are separate failure points, so diagnose them independently. No universal timing or cost figure applies: it depends on the browser environment, proxy service, target site, and capture volume.

5. Or skip the browser setup

If you do not need to manage a Selenium browser and proxy session, ScreenshotNeo captures a URL with one API request. See the API documentation.

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

ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server gives AI agents tools for screenshots, page information, and PDF capture. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.

Create a free ScreenshotNeo account to get 1,000 screenshots a month with no card.

FAQ

Does a proxy change what Selenium captures?

The proxy changes the browser’s network route. Selenium still captures the browser window or document according to the screenshot method you call.

Can I save a screenshot as JPEG with save_screenshot?

The documented Python method saves PNG. If another image format is required, convert the returned PNG bytes with an image-processing library or use a capture service that supports the desired output format.

Can I use Selenium Manager’s proxy setting for website traffic?

No. That setting is for Selenium Manager’s own network connection. Configure the proxy on browser options for page traffic.

Will the same full-page screenshot call work in Chrome and Firefox?

Do not assume so. The full-document methods cited here are documented for Selenium’s Python Firefox driver; check the current API for the browser you use.

Sources