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 DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

How to Set Dark Mode Before Taking a Selenium Screenshot in Chrome

Set Chrome’s emulated prefers-color-scheme to dark through CDP before navigation, then wait for the site’s rendered state before saving a Selenium screenshot.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To capture a website’s own dark theme, set Chrome’s emulated prefers-color-scheme media feature to dark before navigating, then wait for the page to render and take the Selenium screenshot. This asks the site to respond to a dark-mode preference; it does not force a dark theme onto a site that has not implemented one.

Emulate the site’s dark-mode preference with Chrome DevTools Protocol

Chrome’s DevTools Protocol (CDP) command for this is Emulation.setEmulatedMedia. Its payload sets the prefers-color-scheme feature to dark:

As an Amazon Associate I earn from qualifying purchases.

{
  "features": [
    { "name": "prefers-color-scheme", "value": "dark" }
  ]
}

With Selenium’s Python Chrome driver, execute_cdp_cmd sends that command. Apply it before navigation so the preference is in place when the page starts rendering:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait

url = "https://example.com"
options = webdriver.ChromeOptions()

# Add any required Chrome options here, such as headless mode.
driver = webdriver.Chrome(options=options)

try:
    driver.execute_cdp_cmd(
        "Emulation.setEmulatedMedia",
        {
            "features": [
                {"name": "prefers-color-scheme", "value": "dark"}
            ]
        },
    )
    driver.get(url)

    # Replace this with a condition that means the page is ready for your test.
    WebDriverWait(driver, 20).until(
        lambda browser: browser.execute_script(
            "return document.readyState"
        ) == "complete"
    )

    driver.save_screenshot("dark-mode.png")
finally:
    driver.quit()

The wait above checks document loading, not that a particular application has finished changing themes. For a page that renders its theme asynchronously, wait for a page-specific signal—such as a theme attribute or a visible element in the expected state—before saving the screenshot.

#1 Best Overall

Adapt the command to your Selenium language binding

The CDP command and payload are the protocol-level part; how Selenium sends them depends on the language binding and its version. Python Chrome drivers commonly expose execute_cdp_cmd. Java uses Selenium’s DevTools integration, and other bindings have their own APIs. Check the documentation for your installed Selenium binding and Chrome version rather than assuming one invocation works across languages.

Make sure you are testing the dark mode you intend

Emulating prefers-color-scheme: dark tests whether the site responds to the user’s dark color-scheme preference, using its CSS or JavaScript. The browser cannot make a site implement a site-authored dark theme. A site may instead rely on a theme toggle, a saved preference, or server-side selection, so inspect the application’s behavior if the screenshot remains light.

Rank #2
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
  • 256 GB SSD of storage.
  • Multitasking is easy with 16GB of RAM
  • Equipped with a blazing fast Core i5 2.00 GHz processor.
Test mode What it tests Use it for
Emulated prefers-color-scheme: dark The site’s response to a dark color-scheme preference. Checking the site’s own dark CSS or JavaScript.
Chrome automatic dark mode Chrome’s generated dark rendering of web content. Inspecting browser-generated dark treatment, including on a site without its own dark theme.
DevTools Rendering panel Interactive, manual emulation in the current tab. Diagnosing the visual state before automating it.

Chrome’s Rendering panel provides a manual prefers-color-scheme: dark option; refresh the page to inspect its response. The panel’s separate automatic dark mode tests Chrome-generated rendering instead. While automatic dark mode is enabled, Chrome disables the separate prefers-color-scheme selector and sets it to dark automatically.

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

Use a repeatable capture sequence

  1. Create the Chrome WebDriver session. Set the browser options and viewport required by the test.
  2. Apply the CDP emulation. Send Emulation.setEmulatedMedia with prefers-color-scheme set to dark.
  3. Navigate to the target URL. Applying the setting first lets the page see the preference during its initial rendering.
  4. Wait for the expected page state. Use an application-specific condition if client-side code, fonts, images, or other asynchronous work can affect the screenshot.
  5. Capture the screenshot. Call Selenium’s screenshot method after the relevant content is ready.
  6. Reset before testing another mode. If you will use the same session for light-mode tests, clear or change the emulation override, or start a fresh session. The override can affect later pages in that session; confirm reset behavior against the Chrome and protocol versions you use.

Troubleshoot screenshots that do not look dark

  • The screenshot is still light: check whether the site responds to prefers-color-scheme, whether the command was sent to the active Chrome target, and whether an application toggle or saved preference takes precedence.
  • The page changes after capture: wait for the page’s actual theme and content to finish rendering. A document-ready check alone may not cover asynchronous application work.
  • The CDP command fails: confirm the installed Selenium binding supports a CDP command path and that its supported protocol version matches the Chrome/ChromeDriver setup. The command interface is version-sensitive.
  • You want Chrome to darken a page automatically: use Chrome’s automatic dark mode for that test. It is a different test from checking the site’s own response to the emulated preference.
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 is a screenshot API and MCP server. For dark-mode captures, use its dark-mode option; see the ScreenshotNeo documentation for the current request parameters. The following is the supplied one-call cURL example; replace the target URL as needed:

Rank #3
15.6 Inch Win 11 Laptop Computer, N4020, 4GB DDR4 RAM, 128GB Storage
  • WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
  • 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
  • 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
  • CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
  • LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Quick Recap

Bestseller No. 1
HP 14' HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
HP 14" HD Laptop, Windows 11, Intel Celeron Dual-Core Processor Up to 2.60GHz, 4GB RAM, 64GB SSD, Webcam, Dale Pink (Renewed)
14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
$245.99
Bestseller No. 2
Dell Latitude 5420 14' FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
Dell Latitude 5420 14" FHD Business Laptop Computer, Intel Quad-Core i5-1145G7, 16GB DDR4 RAM, 256GB SSD, Camera, HDMI, Windows 11 Pro (Renewed)
256 GB SSD of storage.; Multitasking is easy with 16GB of RAM; Equipped with a blazing fast Core i5 2.00 GHz processor.
$285.00

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.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Leave a Reply

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

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
Outdated Drivers Are Slowing You DownFree scan - exact matches
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.