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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Choose Chrome’s display mode when you create the Selenium WebDriver session: add --headless to the Chrome options for headless mode, or omit it to launch a visible, headed browser. To change modes in a test run, quit the existing session and create another with the options you want; the cited Selenium and Chrome guidance configures the mode at launch rather than describing an in-place switch.

Choose the mode before creating the driver

Headless Chrome runs without a visible browser window. Headed Chrome opens the normal visible browser window. The difference matters most when you need to observe the page or interact with it directly: use headed mode while diagnosing a visual issue or watching a test, and headless mode when a visible window is not needed.

Both modes are launched through Chrome startup options passed to Selenium. Current Chrome documentation uses --headless in its Selenium example. For headed mode, leave that argument out. The relevant choice is the browser’s launch configuration, not a later WebDriver command that toggles a running browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Headless: add --headless to Chrome options.
  • Headed: do not add a headless argument.

There is no evidence in the cited documentation that either mode is universally faster or more reliable. Choose based on visibility needs and compatibility with the Chrome version you run.

Switch modes in JavaScript

Install Selenium’s JavaScript binding and make sure Chrome and the matching ChromeDriver setup are available in your environment. The example below creates a headless session; remove the addArguments('--headless') line to make it headed.

const { Builder } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');

async function run() {
  const options = new chrome.Options();
  options.addArguments('--headless'); // Remove this line for headed Chrome.

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

  try {
    await driver.get('https://example.com');
    console.log(await driver.getTitle());
  } finally {
    await driver.quit();
  }
}

run().catch((error) => {
  console.error(error);
  process.exitCode = 1;
});

For a visible session, keep the rest of the code and omit the headless argument:

const options = new chrome.Options();
// No --headless argument: Chrome launches headed.

The official Selenium JavaScript example follows this pattern: create Chrome options, add --headless when desired, and pass the options to the driver builder. If your application selects a mode dynamically, put the choice in the options before calling build().

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

Switch modes in Python

In Python, add the argument to a ChromeOptions instance before constructing webdriver.Chrome. This example uses Selenium 4’s options-based configuration:

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

options = Options()
options.add_argument("--headless")  # Remove for headed Chrome.

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    print(driver.title)
finally:
    driver.quit()

To run headed, delete the options.add_argument("--headless") line and create the driver with the remaining options. Do not rely on older examples that set options.headless = True; configure the Chrome command-line argument through browser options instead.

Change modes during a test run

A WebDriver session starts Chrome with its configured launch arguments. To move from a headed run to a headless one, or vice versa, close the current session and build a new driver with the other configuration. The same approach works when a test runner chooses a mode from an environment variable or command-line setting.

  1. Finish or stop work in the current session.
  2. Call driver.quit() to end the WebDriver session and its browser.
  3. Create a fresh options object.
  4. Add --headless only for a headless launch.
  5. Build a new Chrome WebDriver with those options.

Do not confuse closing one session and starting another with changing the display mode of an already-running Chrome process. The cited guidance describes mode selection at startup; it does not document an in-place Selenium mode toggle.

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

Use the right headless flag for your Chrome version

Headless flag examples changed over time, so older snippets may not describe the current Chrome setup. Chrome’s current documentation describes unified Headless and headful modes and demonstrates Selenium with --headless. It does not make --headless=new a universal requirement.

Chrome context Flag or implementation detail How to interpret it
Current Chrome documentation --headless Use this for the documented Selenium headless launch. Omit the flag for headed mode.
Chrome 96–108, as described in Selenium’s January 29, 2023 post --headless=chrome Historical guidance for that version range, not a general current instruction.
Chrome 109 onward, as described in the same 2023 post --headless=new Historical transition guidance. Current Chrome documentation now uses --headless.
Chrome 132.0.6793.0 milestone The old Headless implementation became available only as the separate chrome-headless-shell binary. Consider this compatibility distinction if a workflow specifically depends on the old implementation.

These version details are milestones, not a promise that every old flag behaves identically in every later Chrome build. If you maintain a version-pinned environment, check the Chrome documentation for the version you actually deploy rather than copying a flag from an older post.

Use Chrome options, not removed Selenium shortcuts

Selenium’s setHeadless(true) convenience method was deprecated in Selenium 4.8.0 and removed in Selenium 4.10.0. For current Selenium code, use the Chrome options object and add the command-line argument there. Selenium author Diego Molina summarized the approach in a January 29, 2023 post: “In short, users can add the headless mode they want to use through arguments in browser options.” That is historical Selenium API guidance; Chrome’s current documentation is the better reference for today’s Chrome flag.

In practical terms, use the options class for your language binding, add or omit the headless argument, then pass that options object to the WebDriver constructor or builder. This keeps the mode decision visible alongside other Chrome startup settings.

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

Troubleshoot common mode-switching problems

Chrome still opens a visible window

Check that --headless is added to the Chrome options object actually passed to the driver. Confirm it is added before the session is built, and make sure the test is creating a new session rather than reusing an existing one. Remove conflicting or stale configuration in the code path that constructs the driver.

Chrome stays headless when you expect a window

Remove --headless from all Chrome arguments passed to that session, then quit and recreate the driver. Omitting the argument on a running browser cannot retroactively change the launch configuration.

An old sample refers to setHeadless or a property assignment

Update the code to use Chrome options with an argument. setHeadless(true) was removed in Selenium 4.10.0 after deprecation in 4.8.0, and older property-based examples are not the recommended current pattern.

A historical flag behaves unexpectedly

First identify the Chrome version used by the test and compare its flag with current Chrome documentation. Selenium’s 2023 examples distinguished Chrome 96–108 from Chrome 109 onward, but current Chrome documentation uses --headless. Do not treat --headless=new as required for all contemporary versions.

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.

A workflow relies on the old Headless implementation

Check whether the Chrome version is at or beyond 132.0.6793.0. From that documented milestone, the old implementation is available only as the separate chrome-headless-shell binary. A workflow that depends on it may need to provision that binary rather than expect the old implementation in the regular Chrome binary.

The test cannot show a browser window in its environment

Headed mode requires a visible browser window to observe. If the execution environment cannot provide one, run headless for that environment and reproduce the issue in an environment where a visible window is available. The mode decision alone does not diagnose other Chrome or driver startup problems.

Performance and reliability: choose by need, not assumption

The official material reviewed establishes the visibility distinction and flag history, but it does not provide a benchmark showing that headless mode is faster, or that either mode is more reliable. Do not use mode as a substitute for measuring your own test workload. If execution time or failures matter, compare the same test and environment with both configurations and record the results for your own setup.

For reproducible runs, keep the Chrome version and launch options explicit, create a fresh session for each mode, and capture the failure details your test framework already provides. A passing headless run does not by itself demonstrate that a headed session will behave identically for every page or test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a website screenshot rather than Selenium browser automation, ScreenshotNeo is a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF; its capture flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before the shot. Each of those steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in headers.

Example using cURL (replace the target URL as needed):

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

See the ScreenshotNeo documentation for the API and its parameters. It also has an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. Free includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for 1,000 free screenshots a month, no card required.

Frequently Asked Questions

Can I switch a Selenium Chrome session from headless to headed without restarting it?

The cited Selenium and Chrome documentation describes choosing the mode at browser startup, not an in-place Selenium toggle. Quit the session and create a new one with the desired Chrome options.

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

Is --headless=new still required?

No. Current Chrome documentation’s Selenium example uses --headless; --headless=new appears in historical transition guidance.

Does headless Chrome always run faster than headed Chrome?

The cited official sources do not establish a universal speed advantage for either mode.

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.