User Agents

Web browsers and everyday web tech, explained

Chrome Headless Incognito Mode Setup Guide

· 4 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Starting Chrome in headless mode with incognito browsing enables automated tasks like web scraping or testing while preventing persistent data storage such as cookies, history, and cached files. This combination ensures privacy and isolation between sessions, which is essential for reliable automation scripts or avoiding detection. Headless mode runs Chrome without a visible interface, making it ideal for server environments or background processes. Incognito mode adds a layer of session isolation, ensuring no data from previous browsing sessions interferes. This guide walks you through setting it up correctly, avoiding common pitfalls, and troubleshooting when things go wrong.

What You'll Need

  • Google Chrome or Chromium browser installed (version 59 or later)
  • Command-line access (Terminal on macOS/Linux, Command Prompt or PowerShell on Windows)
  • Basic familiarity with command-line arguments and flags
  • Optional: A scripting environment (Node.js with Puppeteer, Python with Selenium, etc.)

Step-by-Step

  1. Open your system’s command-line interface: Terminal (macOS/Linux) or Command Prompt/PowerShell (Windows).
  2. Type google-chrome --headless=new --incognito (Linux), "C:\Program Files\Google\Chrome\Application\chrome.exe" --headless=new --incognito (Windows), or "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" --headless=new --incognito (macOS) to start Chrome.
  3. If you're using an older version of Chrome (before v112), use --headless instead of --headless=new. The newer flag enables improved compatibility with web features.
  4. Add --disable-gpu if running on Windows or certain Linux configurations to prevent rendering issues: --headless=new --incognito --disable-gpu.
  5. Include --no-sandbox only if running in a restricted environment (e.g., Docker without proper sandbox setup). Never use this in production unless absolutely necessary, as it reduces security.
  6. To specify a custom user agent or window size, append additional flags like --user-agent="CustomAgent" or --window-size=1920,1080.
  7. For automation tools like Puppeteer, configure the launch options to include both headless and incognito settings. In Puppeteer, use:
    const browser = await puppeteer.launch({
      headless: 'new',
      args: ['--incognito']
    });
    const page = await browser.newPage();
    
  8. In Selenium (Python), use:
    from selenium import webdriver
    options = webdriver.ChromeOptions()
    options.add_argument('--headless=new')
    options.add_argument('--incognito')
    browser = webdriver.Chrome(options=options)
    
  9. Verify the setup by navigating to a test site and checking that no cookies persist after closing the session.
  10. Close the session properly using browser.close() in automation scripts to free system resources.

Common Mistakes

  • Using --headless without =new on modern Chrome versions, which can cause compatibility issues with certain web features.
  • Forgetting to quote the Chrome executable path on Windows or macOS when it contains spaces, leading to “command not found” errors.
  • Assuming incognito mode disables all tracking—while it blocks local data storage, your IP address and behavior patterns may still be detectable.
  • Running with --no-sandbox by default, which exposes the system to potential exploits, especially in multi-user environments.
  • Not closing browser instances in scripts, leading to memory leaks and multiple orphaned processes.
  • Expecting incognito to hide activity from network administrators or websites—this is not the case; it only isolates local data.

Tips

  • Use --headless=new for better compatibility with modern web applications compared to the legacy headless mode.
  • Combine --incognito with --disable-extensions and --disable-plugins for maximum session isolation.
  • Set a fixed user agent using --user-agent to avoid detection based on inconsistent browser fingerprints.
  • Use --window-size to simulate real user behavior and avoid triggering anti-bot measures.
  • Run Chrome under a dedicated user account or container to further isolate browsing activity.
  • Log console output using --log-level=0 and capture stderr for debugging automation scripts.

Troubleshooting

If Chrome fails to start, first verify the executable path is correct and accessible. On Linux, ensure the google-chrome command is in your PATH or use the full path. If you see a “no DISPLAY environment” error on headless servers, this is expected—Chrome runs without a screen, so ignore it unless the process crashes. If pages fail to load, check network connectivity and firewall settings. Some sites block headless browsers; in such cases, mimic real browser behavior by setting realistic headers, delays, and viewport sizes. If incognito mode seems inactive, confirm that no persistent user data directories are being referenced—avoid using --user-data-dir unless necessary. If Chrome crashes immediately, disable GPU acceleration with --disable-gpu, especially on Windows. For automation scripts, ensure proper async handling and await browser initialization before interacting with pages. Always review Chrome’s command-line flag documentation for version-specific changes.

Frequently Asked Questions

Does headless incognito mode hide my IP address?

No. Incognito mode only prevents local data storage. Your IP address remains visible to websites and network observers.

Can websites detect headless Chrome in incognito?

Yes. Many sites use JavaScript checks to detect headless environments based on missing browser features or behavior patterns, even in incognito.

Is it safe to use --no-sandbox in production?

No. Disabling the sandbox reduces security significantly. Use proper sandbox configuration instead, especially in shared or public environments.

Why does my script hang when launching Chrome?

This often happens if Chrome waits for a display or user input. Ensure --headless=new is used and no interactive prompts are triggered.

Can I save downloads in headless incognito mode?

Yes, but you must configure the download path programmatically. Downloads are not saved automatically and require explicit handling in scripts.

Does incognito mode work the same in headless as in regular Chrome?

Yes. The incognito behavior—no persistent cookies, history, or cache—is preserved in headless mode.