User Agents

Web browsers and everyday web tech, explained

Headless Chrome Modern Mode and Headless Shell Guide

· 5 min read · Browsers

In this article
  1. Understanding the Evolution of Headless Chrome
  2. Headless Shell vs. Modern Headless Mode
  3. Essential Commands and Implementation
  4. Primary Use Cases
  5. Common Problems and Misconceptions
  6. Choosing the Right Mode
  7. Frequently Asked Questions

Headless Chrome modern mode is the current implementation of the Chrome browser that allows it to run without a visible graphical user interface (GUI) while maintaining full parity with the headed version of the browser. Unlike the legacy headless mode, which used a separate, simplified browser engine, the new headless mode (often referred to as "new" or "modern") is essentially the full Chrome browser running with the window hidden. The "headless shell" is a separate, lightweight binary distributed with Chrome that provides a minimal environment specifically for automation, reducing resource overhead by stripping out components unnecessary for non-visual browsing.

Understanding the Evolution of Headless Chrome

For years, Chrome offered a "headless" mode that was a distinct implementation from the browser users saw on their screens. While efficient, this legacy mode often behaved differently than the headed browser, leading to "it works in headed but fails in headless" bugs. This discrepancy occurred because the legacy mode used a separate codebase to simulate the browser environment.

The modern mode solves this by using the same rendering engine, JavaScript execution environment, and network stack as the standard Chrome browser. When you invoke modern headless mode, you are running the actual Chrome browser; the only difference is that the browser does not create a window on the OS desktop. This ensures that what a developer sees during debugging in a headed window is exactly what happens in a production headless environment.

Headless Shell vs. Modern Headless Mode

It is important to distinguish between the --headless=new flag (modern mode) and the chrome-headless-shell binary. While both operate without a GUI, they serve different purposes:

  • Modern Headless Mode (--headless=new): This is the full Chrome browser. It includes all the standard features, extensions support, and the complete rendering pipeline. It is the gold standard for testing because it mirrors the end-user experience perfectly.
  • Headless Shell: This is a stripped-down version of the browser. It removes the browser UI (tabs, address bar, bookmarks) and some of the heavier overhead associated with the full Chrome binary. It is designed for high-performance automation and CI/CD pipelines where memory and CPU usage must be minimized.

Essential Commands and Implementation

To utilize these modes, developers use command-line flags passed to the Chrome executable. Depending on the version of Chrome being used, the flags may vary slightly, but the following are the standard implementations for modern environments.

  1. Launching Modern Headless Mode: To start the full browser in the new headless mode, use the flag --headless=new. This tells Chrome to use the updated headless implementation rather than the legacy one.
  2. Launching the Headless Shell: If you have downloaded the specific chrome-headless-shell binary, you simply execute that binary. It defaults to headless operation and does not require the --headless flag to hide the window.
  3. Combining with Automation: These modes are typically triggered via drivers like Puppeteer or Playwright. For example, in Puppeteer, setting headless: true in the launch options now defaults to the modern implementation in recent versions.
  4. Disabling GPU: In many server environments (like Linux servers without a graphics card), adding --disable-gpu is necessary to prevent the browser from attempting to initialize hardware acceleration, which can cause crashes in headless mode.

Primary Use Cases

The shift to modern headless mode has expanded the reliability of several key automation tasks:

  • Automated Testing (E2E): Modern mode allows developers to run End-to-End (E2E) tests that accurately reflect how a real user interacts with a site, including complex CSS layouts and JavaScript-heavy frameworks.
  • PDF and Screenshot Generation: Because modern mode uses the full rendering engine, it can generate pixel-perfect PDFs and screenshots of web pages, ensuring that the layout is identical to what a user sees in a browser.
  • Web Scraping of Dynamic Content: Many modern websites rely on Client-Side Rendering (CSR). Headless Chrome executes the JavaScript required to render these pages, allowing scrapers to extract data that is not present in the initial HTML source.
  • SEO Auditing: Tools use headless mode to see how search engine crawlers (which often render JavaScript) perceive a page, checking for hidden content or rendering errors that could impact rankings.

Common Problems and Misconceptions

One common misconception is that headless mode is invisible to websites. In reality, websites can often detect headless browsers through "browser fingerprinting." They check for specific properties, such as navigator.webdriver being set to true, or the absence of certain plugins and window dimensions that a real user would have.

Another frequent issue is memory leakage. Because modern headless mode runs the full browser engine, it consumes significantly more RAM than the legacy headless mode or the headless shell. In a CI/CD environment, failing to properly close browser instances (using browser.close()) can quickly lead to "Out of Memory" (OOM) errors on the server.

Choosing the Right Mode

Deciding between the full modern headless mode and the headless shell depends on the priority of the project:

  • Choose Modern Headless (--headless=new) if: You are performing QA testing, verifying visual layouts, or need to ensure 100% compatibility with the user's browser experience.
  • Choose Headless Shell if: You are running thousands of parallel tasks, operating on extremely limited hardware, or performing simple data extraction where visual fidelity is not a requirement.

Frequently Asked Questions

What is the difference between legacy and modern headless mode?

Legacy headless mode used a separate, simplified engine that often behaved differently than the actual Chrome browser. Modern headless mode is the full Chrome browser running without a visible window, ensuring that the behavior, rendering, and JavaScript execution are identical to the headed version.

Does headless Chrome support extensions?

Yes, modern headless mode supports Chrome extensions, whereas the legacy headless mode had very limited or no support for them. This allows developers to test extension functionality or use extensions to modify browser behavior during automation.

Why is my headless browser being detected by websites?

Websites detect headless browsers by checking for specific JavaScript flags, such as navigator.webdriver, or by analyzing the User-Agent string and screen resolution. To mitigate this, developers often use libraries to mask these properties to make the browser appear as a standard headed instance.

Can I switch from headless to headed mode for debugging?

Yes. By simply removing the --headless=new flag or setting headless: false in your automation script, Chrome will launch with a visible GUI. This allows you to see exactly where a script is failing and interact with the page manually.

Is the headless shell faster than modern headless mode?

Generally, yes. Because the headless shell removes the overhead of the browser's user interface and other non-essential components, it typically starts faster and consumes less memory per instance than the full browser in modern headless mode.