Headless browser
A headless browser is a web browser without a graphical user interface.
Headless browsers provide automated control of a web page in an environment similar to popular web browsers, but they are executed via a command-line interface or using network communication. They are particularly useful for testing web pages as they are able to render and understand HTML the same way a browser would, including styling elements such as page layout, color, font selection and execution of JavaScript and Ajax which are usually not available when using other testing methods.
Since version 59 of Google Chrome and version 56 of Firefox, there is native support for remote control of the browser. This made earlier efforts obsolete, notably PhantomJS.
Use cases
The main use cases for headless browsers are:- Test automation in modern web applications
- Taking screenshots of web pages.
- Running automated tests for JavaScript libraries.
- Automating interaction of web pages.
Other uses
Headless browsers have also been misused in various ways:
- Perform DDoS attacks on web sites.
- Increase advertisement impressions.
- Automate web sites in unintended ways e.g. for credential stuffing.
Usage
As several major browsers natively support headless mode through APIs, some software exists to perform browser automation through a unified interface. These include:- Selenium WebDriver – a W3C compliant implementation of WebDriver
- Playwright – a Node.js library to automate Chromium, Firefox and WebKit
- Puppeteer – a Node.js library to automate Chrome or Firefox
Test automation
- Capybara uses headless browsing, either via WebKit or Headless Chrome to mimic user behavior in its testing protocols.
- Jasmine uses Selenium by default, but can use WebKit or Headless Chrome, to run browser tests.
- Cypress, a frontend testing framework
- QF-Test, a software tool for automated testing of programs via the graphical user interface where a headless browser can also be used for testing.
Alternatives
Another is HtmlUnit, a headless browser written in Java. HtmlUnit uses the Rhino engine to provide JavaScript and Ajax support as well as partial rendering capability.
List of headless browsers
These are various software that provide headless browser APIs.- Splash is a headless web browser written in Python using the WebKit layout engine via Qt. It has an HTTP API, Lua scripting support and a built-in IPython -based IDE. Development started at ScrapingHub in 2013; it is partially funded by DARPA.
- Zombie.js is a simulated browser environment for Node.js.
- SimpleBrowser is a headless web browser written in C# supporting.NET Standard 2.0
- DotNetBrowser is a proprietary.NET Chromium-based library that provides the off-screen rendering mode and can be used without embedding or displaying windows.