Headless Browser 101: The most popular headless browsers for automation testing

Are you new to the headless browser technology? Then this page has been written for you. This article is an ultimate guide to headless browsers. You are going to learn what it is, its uses, dark sides, and much more.

ultimate guide to headless browsers

The Internet has evolved, and web automation is taking the front row and increasingly becoming a norm. In fact, it might interest you to know that developers and marketers are actively looking for the repetitive aspect of their workflow to automate in other to free up time for other tasks that can’t be automated. At the center of all of this automation frenzy is headless browser – a technology that brings web browser capabilities, including script rendering and executing JavaScript codes and events, to the command line.

The introduction of headless browsers has not only to make automated web testing possible but also opens up opportunities in web scraping, especially when dealing with Ajaxified and JavaScript rich websites. There are other use cases you can put headless browsers into, and these will be discussed later in the article. For now, sit back and relax as we dive into discussing what headless browsers are.


What is a Headless Browser?

A headless browser is a web browser without a Graphical User Interface (GUI). To put it better, any browser that has the capabilities of a full-fledged web browser but does not have a User Interface and can only be operated using a script or any other software is known as a headless browser.

Headless browsers make it possible to control web browsers without having to deal with the physical loading of the User Interface. Take, for instance, the Google Chrome browser can run in headless mode and carry out evens such as sending web requests, triggering a JavaScript even, clicking buttons, executing custom JavaScript codes, and even make a purchase without actually launching Chrome for you to see.

Headless Browser explained

The importance of headless browsers lies in their capabilities to render and understand HTML, CSS, and JavaScript the way regular browsers do. If you have tried accessing resources online using regular scripts and libraries, you will discover that all they can do is recover HTML documents – understanding and rendering JavaScript code is up to you.

YouTube video

With most modern websites depending largely on JavaScript and Ajax technology, this means that these tools are becoming useless by the day as they can’t access all of the content presents on a page as they should. Well, if you are dealing with a site like that – headless browsers to the rescue.

As stated earlier, the Chrome browser can run in headless mode, and in fact, when discussing headless browsers, headless Chrome is the most popular one available. Some of the popular headless browsers include headless Firefox, PhantomJS, SimpleBrowser, Splash, HtmlUnit, and TrifleJS.

One thing you need to know about these browsers is that they are controlled using command lines and scripts in supported programming languages. The content of the pages they access is also accessible via the command line. For headless browsers to work, they will need a controller or driver with the likes of Selenium, Puppeteer, and Cypress as the popular options.


Headless Browsers Use Cases

Headless Browsers Use Cases

Headless browsers have many use cases that can be summed up into one word – automation. Yes, headless browsers are used for accessing websites in an automated manner – and what you do with that is up to you. Let take a look at some of the few activities you can use headless browsers for.

  • Modern Website and Application Testing

Modern Website and Application Testing

In the past, web pages are static pages, and testing them using does not present any major challenge using traditional HTTP libraries. However, in recent times, things have changed rapidly, and some modern websites have the feel, look, and User Interface of native applications.

With the help of headless browsers, you can render these websites and test them as a developer without doing so manually. Headless browsers should be part of the testing toolbox for the modern-day web developer because of their ability to render JavaScript and fire events that will send Ajax, among others.


  • Web Data Extraction

Web Data Extraction

Websites that depend on JavaScript rendering for the presentation of their content present a challenge to web scrapers and crawlers because their content can only be extracted in a web browser environment. with the help of a headless browser, you have all it takes to render content in other to scrape it.

One of the popular examples of the use of headless browsers for web data extraction is Google using headless Chrome to crawl, and index Ajaxified websites. Another use case of headless browsers in web scraping and crawling is bypassing anti-bot systems. Using a headless browser helps you evade some of the anti-bot systems of websites as all HTTP headers are sent, JavaScript is rendered, and event-triggered.


  • Tasks Automation

Tasks Automation

There are many tasks you can automate aside from web data extraction. Nowadays, you can automate your purchase, fill forms, send messages, reply to them, and even provide near-complete customer service with the aid of a headless browser. If the site you intend to automate your tasks is modern and relies on JavaScript, you will most likely need to make use of a headless browser.


  • Page Screenshotting

Page Screenshotting

Are you looking for a means to screenshot web pages and save the screenshots in picture formats? With a headless browser, you can get a page to load and render completely and then screenshot the screen.


Why Use a Headless Browser?

It might interest you to know that regular browsers can be automated to carry out all of the tasks that a headless browser will. Why then will you want to make use of a headless browser instead of a regular browser with a GUI?

It might interest you to know that even at the time of developing an application that utilizes a headless browser, you will need to make use of a browser with GUI for testing and debugging. But the moment the development of the application is complete, you ditch the GUI.

Headless Browser uses

It turns out that headless browsers are faster than regular browsers because of the fact that no GUI is created, and as such, less memory, time, and resources are consumed. It is also important you know that headless browsers are the only browsers you can use on machines and platform that is accessible only via the command line as in the case of some Linux distribution and servers.


Top Headless Browsers for Automation

We have been mentioning headless browsers; it is time to describe some of the best headless browsers. We will be looking at 3 of them below.

Headless Chrome

When the term headless Chrome is mentioned, it does not mean that it is a separate browser from Chrome – it is a mode in the regular Chrome web browsers, you know. The headless mode in Chrome brings all the modern web features of Chromium and the Blink rendering engine to the command line.

The headless mode is supported by the latest versions of Chrome and first appeared in version 59. Headless mode is supported on Linux, macOS, and Windows. It is supported by most browser automation tools, including Selenium and Puppeteer.

YouTube video


Headless FirefoxHeadless Firefox is just like a mode in Firefox, just like in Chrome. It has been supported on Linux since version 55. Headless mode support for Windows and Linux gets added in version 56.

Selenium is one of the best web browser controller for headless Firefox. With headless Firefox, you have access to all the Firefox features except for the GUI – but with the reduction in memory and resource usage.

YouTube video


PhantomJSAside from mainstream browsers such as Chrome and Firefox, PhantomJS is one of the most popular headless browsers. Unlike the other two mentioned above available via headless mode support, PhantomJS is only available as a headless browser. PhantomJS has been around since 2010 and has been used a lot.

However, it is no longer under active development and has been archived. But it can still be used as a headless browser to interact with the modern web. PhantomJS makes use of WebKit for web page rendering and JavaScriptCore for executing scripts.

YouTube video

Still, there are more choices for Zombie.js, HtmlUnit, Jsdom, and Splash, but not so popular when compared to Headless Chrome, Headless Firefox, and PhantomJS.


Headless Browsers and Anti-Bot Systems

Make no mistake about it, except you are using a headless browser on sites you have control over; you will most likely get interrupted and blocked by anti-bot systems of sites. This is because headless browsers are known for automated access only – and not all web services allow automated access.

Even Google that makes use of headless Chrome for crawling Ajax pages would not allow you to use the same headless Chrome to access Google services except via their official APIs.

Headless Browsers with Anti-Bot Systems

For this reason, you will need to incorporate anti-bot bypassing techniques if you are dealing with sites with anti-bot systems in place. Interestingly, unlike other tools, evading anti-bot systems using headless browsers is easy and stress-free.

This is because it is a regular browser, and as such, the major indices that will give it out will be IP address and Captcha.

Interesting, there is an easy walkaround method to bypass these – Crawlera or any other proxy API to the rescue.


Headless Browsers + Crawlera: A Match Made in Heaven for Web Scraping

As stated earlier, anti-bot systems of websites will block traffic originating from a bot. Considering the fact that most scripts that make use of headless browsers are either bots or have bot features, it is wise to expect blocks and then plan on how to circumvent them.

With the use of proxy servers, you can take care of the IP based restrictions while Captcha solvers will help you deal with Captcha. However, going this route will be a lot of work. You can just make use of Crawlera to get it done.

Headless Browsers with Crawlera

Crawlera is a proxy API developed by Scrapinghub for web scraping. Under the hood, Crawlera is a proxy service – but unlike regular proxies, Crawlera has been designed to help you evade anti-bot systems.

In fact, with this service, you do not have to worry about proxy management, IP rotation, throttling, and all of that. Just send a request and get back the response – it is as simple as that as a result of Crawlera’s in-house system of bypassing anti-bot systems. It does not only mask your real IP address and rotate the IP address it assigns to your requests but also takes care of Captchas.

One thing you will come to like about Crawlera is that pricing is based on successful requests, and as such, you only pay for successful requests. With Crawlera, you can enjoy 10K free trials for a limited time. Crawlera is not the only proxy API or scraping API in the market; there are many others, including ScrapingAPI and ScrapingBee. You can make use of the proxy APIs mentioned together with a headless browser and scrape Ajaxified websites.


Are Headless Browsers Illegal?

Headless Browser legalities

I have seen many newbies asking if the use of headless browsers is illegal – in fact, it is even one of the listed questions on the Google result page for the headless browser keyword. The short answer to the question is NO. headless browsers are not illegal – they are just a tool for automating web actions.

It is what you do with it that makes it illegal or not. Take, for instance, web scraping on a general base is considered legal provided the data being scraped is publicly available, not copyrighted, and does not require a login to access.

On the other hand, ticket scalping, Distributed Denial of Service (DDoS) attacks, ad fraud, and other forms of malicious activities that can be done using headless browsers are illegal.

So, headless browsers are not illegal – it is what you use them for that could put you in legal trouble. It is important you know that this is not a piece of legal advice, and it will be better if you seek such from a legal practitioner.

Conclusion

Headless Browser

Headless browsers take away the browser GUI and the resources it consumes, such as memory. With a headless browser, you can bring the HTML rendering and JavaScript execution capabilities of modern web browsers to the command line.

The features it brings to the command line has opened up a lot of opportunities not only to web developers that use it for automated web testing but also bot developers. Aside from headless browsers, there are some other tools that can be used in place of headless browsers, such as simulated browser environments like Zombie.js and ENVJS.