What are Chrome Command Line Switches?

Chrome and Chromium-based browsers support a wide range of command-line switches that allow you to customize browser behavior. These switches are especially useful for automated testing, debugging, and development purposes.

When using ChromeDriver for Selenium WebDriver tests, you can pass these command-line switches through the args capability in ChromeOptions.

How to Pass Command-Line Arguments via ChromeDriver

ChromeDriver provides two key capabilities for managing command-line switches:

The args Capability

Use the args capability to pass a list of command-line arguments when starting Chrome. Arguments with values should use an equals sign (=) as a separator.

# Python Example
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--user-data-dir=/tmp/temp_profile")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--headless=new")

driver = webdriver.Chrome(options=chrome_options)
// Java Example
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("user-data-dir=/path/to/profile");
options.addArguments("disable-gpu");
options.addArguments("headless=new");

WebDriver driver = new ChromeDriver(options);
// JavaScript/Node.js Example
const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

let options = new chrome.Options();
options.addArguments('--start-maximized');
options.addArguments('--user-data-dir=/tmp/temp_profile');
options.addArguments('--disable-gpu');
options.addArguments('--headless=new');

let driver = await new Builder()
  .forBrowser('chrome')
  .setChromeOptions(options)
  .build();

The excludeSwitches Capability

ChromeDriver automatically passes certain switches when starting Chrome. Use excludeSwitches to prevent specific default switches from being applied. Do not prefix switches with -- when using this capability.

# Python Example - Exclude default switches
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation", "enable-logging"])

driver = webdriver.Chrome(options=chrome_options)
// Java Example - Exclude default switches
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("enable-automation", "enable-logging"));

WebDriver driver = new ChromeDriver(options);

Common Chrome Command-Line Switches for Testing

Below is a comprehensive reference of the most useful Chrome command-line switches organized by category.

Window and Display

Switch Description
--start-maximized Start Chrome with a maximized window
--start-fullscreen Start Chrome in fullscreen mode
--window-size=width,height Set initial window size (e.g., --window-size=1920,1080)
--window-position=x,y Set initial window position
--kiosk Run Chrome in kiosk mode (fullscreen without UI)
--force-device-scale-factor=N Override device scale factor (e.g., =2 for retina)

Headless Mode

Switch Description
--headless=new Run Chrome in new headless mode (recommended)
--headless Run Chrome in legacy headless mode
--disable-gpu Disable GPU hardware acceleration (often used with headless)
--screenshot=FILE Take a screenshot and save to file (headless only)
--print-to-pdf=FILE Print the page to PDF (headless only)

User Profile and Data

Switch Description
--user-data-dir=PATH Set custom user data directory for profile
--profile-directory=NAME Use a specific profile directory name
--incognito Start Chrome in incognito mode
--guest Start Chrome in guest mode
--disable-extensions Disable all Chrome extensions

Security and Permissions

Switch Description
--no-sandbox Disable sandbox mode (use with caution, often needed in Docker)
--disable-web-security Disable same-origin policy (for testing only)
--allow-insecure-localhost Ignore TLS/SSL errors on localhost
--ignore-certificate-errors Ignore SSL certificate errors
--allow-running-insecure-content Allow mixed content on HTTPS pages
--disable-popup-blocking Disable popup blocking
--disable-notifications Disable notification permission prompts
--auto-accept-camera-and-microphone-capture Auto-accept camera/microphone permissions

Network and Proxy

Switch Description
--proxy-server=HOST:PORT Use specified proxy server
--proxy-bypass-list=HOSTS Comma-separated list of hosts to bypass proxy
--no-proxy-server Don't use a proxy server, always make direct connections
--host-resolver-rules=RULES Custom DNS resolution rules
--disable-background-networking Disable background network requests

Performance and Debugging

Switch Description
--remote-debugging-port=PORT Enable remote debugging on specified port
--auto-open-devtools-for-tabs Automatically open DevTools for each tab
--enable-logging Enable logging to stderr
--log-level=N Set log level (0=INFO, 1=WARNING, 2=ERROR)
--disable-dev-shm-usage Disable /dev/shm usage (helps in Docker containers)
--disable-infobars Disable info bars (deprecated in newer versions)

Media and Audio

Switch Description
--mute-audio Mute all audio output
--use-fake-ui-for-media-stream Use fake UI for media stream requests
--use-fake-device-for-media-stream Use fake devices for media capture
--autoplay-policy=no-user-gesture-required Allow autoplay without user interaction
--disable-accelerated-video-decode Disable GPU video decoding

Feature Flags and Experiments

Switch Description
--enable-features=FEATURES Enable specified features (comma-separated)
--disable-features=FEATURES Disable specified features (comma-separated)
--enable-blink-features=FEATURES Enable Blink runtime features
--disable-blink-features=FEATURES Disable Blink runtime features

Downloads

Switch Description
--safebrowsing-disable-download-protection Disable Safe Browsing download protection
--disable-default-apps Disable default apps on first run

Common Testing Configurations

Here are some recommended combinations of switches for common testing scenarios:

Docker / CI Environment

# Recommended switches for Docker/CI
chrome_options.add_argument("--headless=new")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--window-size=1920,1080")

Media Testing (WebRTC, Video Calls)

# Switches for testing media features
chrome_options.add_argument("--use-fake-ui-for-media-stream")
chrome_options.add_argument("--use-fake-device-for-media-stream")
chrome_options.add_argument("--auto-accept-camera-and-microphone-capture")
chrome_options.add_argument("--autoplay-policy=no-user-gesture-required")

Clean Test Environment

# Switches for isolated test environment
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--disable-notifications")

Using Chrome Switches with TestingBot

When running your Selenium tests on TestingBot, you can pass Chrome command-line switches through the ChromeOptions capability:

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

chrome_options = Options()
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-notifications")

capabilities = {
    "browserName": "chrome",
    "browserVersion": "latest",
    "platformName": "WIN10",
    "tb:options": {
        "key": "your_key",
        "secret": "your_secret",
        "name": "My Test"
    }
}
chrome_options.set_capability("tb:options", capabilities["tb:options"])

driver = webdriver.Remote(
    command_executor="https://hub.testingbot.com/wd/hub",
    options=chrome_options
)

Note: Some switches may not work in cloud testing environments due to security restrictions. TestingBot provides alternative capabilities for many common use cases. Check the TestingBot documentation for more information.

TestingBot Logo

Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

Start Free Trial

Other Questions