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

To capture a high-density screenshot with Selenium on Linux, set the browser’s CSS-pixel viewport and Chrome’s device scale factor separately, then verify the saved image dimensions. Xvfb supplies a virtual display for a graphical browser; changing its screen size or DPI alone does not establish that Chrome will produce a Retina-sized image.

What “Retina screenshot” means in this setup

A Retina-style capture generally means rendering a given CSS-pixel viewport at a higher device-pixel density. For example, a 1440 × 900 CSS viewport with a device scale factor of 2 has a target output of roughly 2880 × 1800 pixels if the browser’s screenshot path honors that emulation. Treat this as a target to check, not a guaranteed result for every Chrome version or capture method.

  • Xvfb geometry and DPI: Xvfb provides a virtual X display and screen for graphical applications. These settings describe the virtual display.
  • Browser viewport: Selenium can set browser window dimensions, which determine the browsing area in CSS pixels.
  • Device scale factor: Chrome DevTools Protocol (CDP) exposes a browser-side setting for emulating device metrics, including device scale factor.

These are related but distinct controls. The Selenium Docker startup script shows one Xvfb configuration, while the Chrome DevTools Protocol reference documents the browser-side scale factor.

Choose Xvfb or Chrome headless

Use Xvfb when a graphical browser is needed

Use Xvfb when your CI or Linux host must run a graphical browser process without a physical display, or when the test specifically depends on an X display-backed browser. In the Selenium Docker image, the startup script reads SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, and SCREEN_DPI (with SE_-prefixed fallbacks) and passes the resulting screen configuration to xvfb-run. Those variable names and behaviors describe that repository script, not a universal Xvfb interface. Pin the Selenium image release or commit if you depend on them.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Use headless when no X display is required

Chrome headless runs without a visible UI and can take screenshots without Xvfb. Chrome documents headless screenshot and window-size options; its newer virtual-screen documentation also discusses size and scale, but shows Puppeteer examples, not a Selenium recipe. Confirm that your pinned Chrome and Selenium versions support the method you choose.

Choose the mode that matches the behavior you need to test. In either mode, verify that device-scale emulation reaches the screenshot API you use and that dimensions and rendering remain stable in your pinned CI image.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Set up a reproducible Selenium capture

  1. Pin the stack. Record the Selenium, Chrome, ChromeDriver, and—if applicable—Selenium standalone container versions. Headless behavior and compatibility can vary across releases. Selenium’s Chrome-specific documentation discusses compatibility, but check your own pinned versions rather than assuming a newer combination behaves identically.
  2. Start the display if needed. For an Xvfb-backed graphical browser, choose a screen large enough for the intended browser window. In Selenium’s Docker image, configure the variables described above. A large screen or high Xvfb DPI is not, by itself, a documented way to double Chrome screenshot pixels.
  3. Set the CSS viewport. Resize the Selenium browser window to the width and height your test expects. Selenium’s window documentation covers sizing operations and screenshot capture.
  4. Set Chrome device metrics. Apply CDP Emulation.setDeviceMetricsOverride with the intended width and height and a scale factor such as 2. CDP documents this control, but the sources do not establish a Selenium binding call that is stable across every Selenium release; use the approach supported by your pinned binding and verify it in that environment.
  5. Navigate and wait for the right state. Wait for the page state and any assets material to your test before capturing. A screenshot taken before fonts, images, or application content finish loading may have the correct dimensions but the wrong visual result.
  6. Save and inspect the file. Use the screenshot API for your binding, then check the PNG’s actual width and height. Where useful, inspect window.devicePixelRatio and window.innerWidth in the page as additional diagnostics.

Python example: apply CDP metrics and save a screenshot

This example shows the intended sequence for a pinned Selenium Python and Chrome setup. The CDP command is version-sensitive: confirm the command works with your Chrome and Selenium releases, and do not treat the example as a binding guarantee across all versions.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
# For a graphical browser on Linux, run under the X display provided by Xvfb.
# To use Chrome headless instead, configure the headless option supported by
# your pinned Chrome release.
driver = webdriver.Chrome(options=options)

try:
    width, height = 1440, 900
    driver.set_window_size(width, height)

    # Chrome DevTools Protocol browser-side device metrics emulation.
    driver.execute_cdp_cmd(
        "Emulation.setDeviceMetricsOverride",
        {
            "width": width,
            "height": height,
            "deviceScaleFactor": 2,
            "mobile": False,
        },
    )

    driver.get("https://example.com")
    # Replace with an explicit wait for the page state or assets your test needs.
    driver.save_screenshot("retina.png")

    print("innerWidth:", driver.execute_script("return window.innerWidth"))
    print("devicePixelRatio:", driver.execute_script("return window.devicePixelRatio"))
finally:
    driver.quit()

Replace the example URL with the page under test and add explicit waits appropriate to its content. The viewport and scale values configure the capture target; inspect retina.png to establish the actual output dimensions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Verify the result rather than infer it from settings

Check both the browser and image output. A browser-reported device pixel ratio helps confirm that the page sees the intended emulation; the image’s pixel dimensions establish what the chosen screenshot path actually wrote. If either differs from the target, test the same pinned browser and capture method outside the full CI pipeline to isolate configuration from application timing.

  • Confirm the window or viewport dimensions match the intended CSS-pixel area.
  • Confirm window.devicePixelRatio reflects the intended scale in the page.
  • Inspect the PNG’s width and height with an image viewer or image-inspection utility.
  • Repeat after Chrome, ChromeDriver, Selenium, or container-image upgrades; do not assume output behavior is unchanged.

Troubleshooting common Retina screenshot problems

The image is the expected viewport size, not twice as large

Increasing Xvfb DPI or screen geometry does not itself configure Chrome’s device scale factor. Apply browser-side device metrics and check whether the chosen screenshot method honors them. Compare the page’s devicePixelRatio with the saved file dimensions.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient

The browser window cannot reach the requested size

Ensure the Xvfb screen is large enough for the browser window and its chrome, and set the Selenium window size explicitly. In a container, check which screen variables the specific startup script recognizes; variable names in one image are not universal Xvfb options.

The CDP command fails

Check that the browser is Chrome and that your Selenium binding supports the CDP command interface used in the example. Align Selenium, Chrome, and ChromeDriver versions, and consult documentation for those pinned releases. The protocol reference is tip-of-tree documentation, so it may not exactly describe an older Chrome build.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

The screenshot dimensions are correct but the page looks incomplete

Wait for the relevant page state and assets before capturing. Use a condition tied to the element or content your test needs instead of relying on an arbitrary short delay.

Headless and Xvfb produce different results

They are different execution paths. Check that both use the same browser version, viewport, device-scale emulation, page readiness condition, and screenshot API. Keep the mode that matches the application behavior under test and is stable in your pinned CI environment.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a one-request capture, ScreenshotNeo accepts a URL and returns an image or PDF. Its clean-shot steps accept cookie and consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server with screenshot tools for AI agents.

Example cURL request (see the ScreenshotNeo API documentation):

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo’s free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Learn more at ScreenshotNeo, or sign up free.

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.