2025, Oct 05 09:00

How to Run Selenium Chrome in Headless Mode and Suppress Logs from ChromeDriver, Selenium, and Chrome

Learn to run Selenium Chrome headless and keep console output clean by silencing ChromeDriver, Selenium, and Chrome logs. Ideal for CI pipelines and automation.

Running Selenium Chrome in headless mode while silencing the noisy startup logs often looks like a simple toggle, until it isn’t. A common pitfall is that only one goal seems to work at a time: either headless is active but logs spill everywhere, or logs are suppressed but the browser pops up. The root cause is that the messages come from different layers, and you need to quiet each one explicitly.

Reproducing the issue

The following snippet conditionally enables headless and attempts to keep logs quiet via Chrome options, yet you’ll still see output under certain runs:

import sys
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
chrome_prefs = webdriver.ChromeOptions()
chrome_prefs.add_experimental_option("excludeSwitches", ["enable-logging"])  
if not ("-dhl" in sys.argv or "--disable-headless" in sys.argv):
    chrome_prefs.add_argument("--headless=new")
browser_client = webdriver.Chrome(
    service=Service(ChromeDriverManager().install()),
    options=chrome_prefs
)
browser_client.get("https://google.com")

What’s actually happening

The output you see is not a single stream. There are ChromeDriver process logs, Python library logs from urllib3, selenium, WDM and webdriver-manager, and Chrome’s own logging. Turning on headless mode doesn’t silence the driver, and muting Python loggers won’t stop the driver process from writing to its own output. That’s why it looks like you can only “get one thing working” at a time.

The fix: silence each source of messages explicitly

First, direct ChromeDriver’s output to an OS null device so the driver itself stops writing to your console. Then reduce verbosity for the Python-side loggers, and nudge Chrome’s logging level down. Together, these steps allow you to run headless and keep your console clean at the same time.

import os
import sys
import logging
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
chr_flags = webdriver.ChromeOptions()
chr_flags.add_experimental_option("excludeSwitches", ["enable-logging"])  
if not ("-dhl" in sys.argv or "--disable-headless" in sys.argv):
    chr_flags.add_argument("--headless=new")
chr_flags.add_argument("--log-level=3")
svc = Service(
    ChromeDriverManager().install(),
    log_output=os.devnull
)
logging.getLogger("selenium").setLevel(logging.CRITICAL)
logging.getLogger("urllib3").setLevel(logging.CRITICAL)
logging.getLogger("WDM").setLevel(logging.CRITICAL)
logging.getLogger("webdriver_manager").setLevel(logging.CRITICAL)
client = webdriver.Chrome(service=svc, options=chr_flags)
client.get("https://google.com")

If you prefer a more aggressive approach for the Python side, set the root logger instead so everything below CRITICAL and FATAL is filtered out:

import logging
logging.getLogger().setLevel(logging.CRITICAL)

Be aware that some messages such as the “DevTools listening …” line are currently difficult to suppress entirely. This is a known limitation.

Why this matters

Headless runs are the backbone of CI pipelines and server-side automation. Clean logs make failures obvious, speed up triage, and keep noise out of artifacts. Understanding that different subsystems emit output independently saves time you’d otherwise spend toggling the same flags back and forth.

Additional notes

If you need to go even further, redirecting stderr at the process level can quiet residual messages, but it can also hide important errors later. Use with caution:

import os, sys
sys.stderr = open(os.devnull, "w")

Separately, it’s worth noting that webdriver_manager is outdated and unsupported. Selenium provides its own mechanism for downloading and managing drivers, called Selenium Manager. While not directly related to suppressing logs, it’s a good direction for maintaining your setup going forward.

Conclusion

The key to running headless Chrome silently is to treat logging as a multi-source problem. Route ChromeDriver output to os.devnull, reduce verbosity for urllib3, selenium, WDM, and webdriver-manager, and turn down Chrome’s own verbosity. With those pieces in place, headless execution and a quiet console stop being mutually exclusive.

The article is based on a question from StackOverflow by Ahmad and an answer by 0ro2.