Table of contents

What are the command-line arguments to launch Headless Chromium?

To launch Chromium (or Google Chrome) in headless mode via the command line, you need specific command-line arguments. Headless mode runs the browser without a graphical user interface, making it ideal for automated tasks, testing, and server environments.

Basic Command Structure

Here are the essential command-line arguments to launch headless Chromium:

chromium --headless --disable-gpu --remote-debugging-port=9222 http://example.com

Essential Arguments Explained

Core Arguments

  • --headless: Enables headless mode (runs without GUI)
  • --disable-gpu: Disables GPU hardware acceleration (required for stability in headless mode)
  • --remote-debugging-port=9222: Opens debugging protocol on port 9222 for programmatic control
  • http://example.com: Optional URL to navigate to on startup

Security Arguments

  • --no-sandbox: Disables the security sandbox ⚠️ Use with caution - reduces security
  • --disable-web-security: Disables web security features ⚠️ Only for development/testing
  • --disable-features=VizDisplayCompositor: Prevents certain rendering issues

Recommended Production Command

For production environments, use this secure configuration:

chromium --headless --disable-gpu --disable-dev-shm-usage --no-first-run --disable-extensions --disable-default-apps --remote-debugging-port=9222

Additional Useful Arguments

  • --disable-dev-shm-usage: Prevents shared memory issues in Docker containers
  • --no-first-run: Skips first-run experience
  • --disable-extensions: Disables all extensions
  • --disable-default-apps: Disables default applications
  • --window-size=1920,1080: Sets viewport size for screenshots
  • --user-data-dir=/tmp/chrome-user-data: Specifies custom user data directory

Platform-Specific Examples

Windows

"C:\Program Files\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --remote-debugging-port=9222 http://example.com

macOS

/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --remote-debugging-port=9222 http://example.com

Linux (Ubuntu/Debian)

google-chrome --headless --disable-gpu --remote-debugging-port=9222 http://example.com

Linux (Chromium)

chromium-browser --headless --disable-gpu --remote-debugging-port=9222 http://example.com

Docker Environment Example

For containerized environments, use these additional flags:

chromium --headless --disable-gpu --disable-dev-shm-usage --no-sandbox --disable-setuid-sandbox --remote-debugging-port=9222

Testing Connection

After launching with --remote-debugging-port=9222, verify the connection:

curl http://localhost:9222/json/version

Web Scraping Integration

With Puppeteer (Node.js)

const puppeteer = require('puppeteer');

const browser = await puppeteer.launch({
  headless: true,
  args: [
    '--disable-gpu',
    '--disable-dev-shm-usage',
    '--no-sandbox',
    '--disable-setuid-sandbox'
  ]
});

With Selenium (Python)

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

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')

driver = webdriver.Chrome(options=chrome_options)

Security Best Practices

  1. Avoid --no-sandbox in production when possible
  2. Use isolated user data directories with --user-data-dir
  3. Limit network access with firewall rules
  4. Run in containers for additional isolation
  5. Use specific port ranges for debugging protocols

Troubleshooting Common Issues

  • Crashes on startup: Add --disable-dev-shm-usage and --no-sandbox
  • Memory issues: Use --max_old_space_size=4096 for Node.js applications
  • Font rendering problems: Install fonts or use --disable-font-subpixel-positioning
  • Docker issues: Ensure container has sufficient shared memory (--shm-size=2g)

For production web scraping, consider using higher-level libraries like Puppeteer, Playwright, or Selenium WebDriver, which handle these command-line arguments automatically and provide more robust APIs for browser automation.

Try WebScraping.AI for Your Web Scraping Needs

Looking for a powerful web scraping solution? WebScraping.AI provides an LLM-powered API that combines Chromium JavaScript rendering with rotating proxies for reliable data extraction.

Key Features:

  • AI-powered extraction: Ask questions about web pages or extract structured data fields
  • JavaScript rendering: Full Chromium browser support for dynamic content
  • Rotating proxies: Datacenter and residential proxies from multiple countries
  • Easy integration: Simple REST API with SDKs for Python, Ruby, PHP, and more
  • Reliable & scalable: Built for developers who need consistent results

Getting Started:

Get page content with AI analysis:

curl "https://api.webscraping.ai/ai/question?url=https://example.com&question=What is the main topic?&api_key=YOUR_API_KEY"

Extract structured data:

curl "https://api.webscraping.ai/ai/fields?url=https://example.com&fields[title]=Page title&fields[price]=Product price&api_key=YOUR_API_KEY"

Try in request builder

Related Questions

Get Started Now

WebScraping.AI provides rotating proxies, Chromium rendering and built-in HTML parser for web scraping
Icon