Scrapeless Wiki

What Is a Headless Browser? – Definition and How It Works

Informational P1 what is a headless browser
Overlaps a live page. A published page already targets this keyword: https://www.scrapeless.com/en/glossary/headless-browser. Publishing both risks cannibalisation β€” decide before this goes live.

Learn what a headless browser is, which tools drive one, when it is worth its cost, and how it differs from an HTTP client for scraping and testing.

A headless browser is a real web browser that runs without a visible window, controlled by code instead of by a person. It exists because servers have no screens and scripts have no hands.

1. What Is a Headless Browser?

It is a full browser engine running without its graphical interface.

  • Key idea: the same engine, minus the window.
  • Mechanism: the browser runs with a remote debugging port; a library sends commands and receives events.
  • Goal: execute and interact with pages exactly as a browser does, in an environment with no display.

Everything a browser does β€” networking, cookies, JavaScript, layout, rendering β€” still happens. Only presenting frames to a monitor is skipped.

2. The Tools

Tool Language support Notes
Playwright JS/TS, Python, Java, .NET Chromium, Firefox, WebKit; auto-waiting
Puppeteer JS/TS Chromium-focused, thin layer over CDP
Selenium Java, Python, C#, Ruby, JS, more W3C WebDriver; broadest browser coverage

All three can run their browsers headless or headful. Headless is a launch flag, not a separate product.

3. When You Need One

  • Client-rendered content. If the HTML arrives as an empty shell and JavaScript builds the page, only a browser will produce the content.
  • Interaction is required. Logging in, clicking through steps, dismissing modals, triggering infinite scroll.
  • Visual output. Screenshots and PDFs need real layout.
  • Testing. You want the engine users actually run.
  • Complex client-side state. Flows depending on storage, service workers or WebSockets.

4. When You Do Not

This is the more valuable half of the decision, because browsers are the expensive option.

  • The HTML already contains the data. Server-rendered pages need only a fetch.
  • There is an internal JSON endpoint. Most "JavaScript-heavy" pages fetch their data from an API you can call directly. Open DevTools β†’ Network β†’ Fetch/XHR and reload β€” that endpoint is usually cleaner, smaller and more stable than the rendered DOM.
  • There is a documented API. Always check first.
  • Volume is high and the target is simple. Thousands of pages through browsers costs orders of magnitude more than through an HTTP client.

Example to Illustrate

A page renders a product grid client-side. The browser route launches Chromium, waits for network idle, and parses the DOM β€” around two seconds and 200 MB. The alternative is one request to the /api/products?page=1 call the page itself makes, returning clean JSON in 80 ms.

Both produce the same data. Only one scales.

5. Browser vs. HTTP Client

HTTP client Headless browser
Executes JavaScript No Yes
Memory per unit Kilobytes 100–300 MB
Time per page Tens of ms Hundreds of ms to seconds
Concurrency per machine Thousands Dozens
Gets client-rendered content No Yes
Screenshots No Yes
TLS fingerprint Library's, unless impersonating Genuine browser

6. Running Them in Production

  • Reuse instances. Launching per page dominates cost; keep a pool.
  • Isolate with contexts, not new browsers β€” separate cookies and storage at a fraction of the price.
  • Block what you do not need. Images, fonts, media and analytics are often most of the bytes.
  • Recycle regularly. Long-lived instances leak memory and accumulate state.
  • Cap page lifetime. A page that never reaches network idle will hang forever without a timeout.
  • Containers need configuration. Shared memory limits and missing fonts cause failures that look like page bugs.

7. Detectability

A headless browser is a real browser, but its environment often is not a real user's. Software rendering exposed through WebGL, absent GPU, default window sizes, and interactions with no mouse movement all read as automated.

Modern Chrome headless closed much of the historic gap by using the same binary as headful. What remains is mostly environmental and behavioural rather than a flag to unset.

8. Summary

A headless browser is a complete browser without a visible window, driven over a debugging protocol by Playwright, Puppeteer or Selenium. It executes JavaScript, maintains state, interacts with pages, and renders β€” everything except display.

It is the right tool when a page genuinely requires execution or interaction, and the wrong one when a fetch or an internal JSON endpoint would do. The cost difference is not marginal: hundreds of megabytes and seconds per page against kilobytes and milliseconds. Check for the endpoint first; reach for the browser when the page leaves no alternative.