Tutorial to Install Google Chrome Headless on Ubuntu Linux to use the browser without GUI on the command line terminal.
What is a headless browser?
A headless browser means a web browser without a graphical user interface. This implies the users can access the webpages but in the command line interface, not in a graphical user interface. Headless browsers are particularly used by developers and system administrators for testing web pages. It is because in headless they can understand the rendering of HTML in a better way 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.
Well, in Google Chrome and FireFox, apart from the Graphical user interface, headless support is also there out of the box.
Using Google Chrome headless or other browsers we can perform automation testing of web apps, javascript libraries; the interaction of web pages, and even save the website page in PDF or can take screenshots. Headless browsers are also useful in web scraping.
Remember Headless browsers are not Text-based browsers both are different except one thing in common is the command line Interface…
Install and Use Google Chrome headless on Ubuntu Linux
The steps given here to install Google Chrome and use it as a Headless browser on Ubuntu will also work for Debian. And other similar Linux such as Linux Mint, POP OS, Zorin OS, and more…
1. Download Google Chrome Deb
We cannot install Google Chrome using the default system repository of Ubuntu. It is because Chrome is a proprietary software. Therefore, we manually have to download the Debian binary of the chrome browser. Open the command terminal or if you are on Server edition with CLI then you are already there. After that run the given command:
First, install Wget:
sudo apt update
sudo apt install wget
Now, download the Chrome deb binary.
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
2. Install Google Chrome Browser on Ubuntu
Next, we use the default system package manager which is APT to install the Chrome Deb package of Google’s browser on our Ubuntu Linux system. For that in your terminal, use the given command.
sudo apt install ./google-chrome-stable_current_amd64.deb
3. Starting Ubuntu Chrome Headless mode
The headless mode comes by default in Google Chrome browser since version 59. Therefore to use it, in your command terminal use --headless
flag along with other parameters.
For example to print the DOM (Document Object Model )
We use --dump-dom
flag that will print the HTML body of a webpage:
google-chrome-stable --headless --dump-dom https://www.how2shout.com
For remote debugging we can use the following flag:
--remote-debugging-port=9222
Note: Change the URL of the site you want to test.
4. To save a webpage in PDF
If you want then we can use the Chrome headless mode to save some website pages in PDF format. For that, we have to use --print-to-pdf
flag
google-chrome-stable --headless --disable-gpu --print-to-pdf https://www.how2shout.com/
It will save the webpage as output.pdf.

5. Use Chrome Headless to take screenshots
Let’s say you want to take a screenshot of a webpage but as it appears to the whole world in graphical format. Then that is also possible using a flag --screenshot
For 800 × 600 pixels size, you can use:
google-chrome-stable --headless --screenshot https://www.how2shout.com/
For the letterhead size screenshot, we need to mention the size using --windows-size
flag.
google-chrome-stable --headless --screenshot --window-size=1280,1696 https://www.how2shout.com/
The command will save the screenshot in your current directory as screenshot.png
Other Articles:
⇒ How to install Dropbox GUI or Headless on Ubuntu 20.04 LTS
⇒ Install Chrome browser on Debian 11 Bullseye Linux
⇒ 2 Ways to install Google Chrome browser on AlmaLinux 8
⇒ 2 ways to install Chrome Browser on Ubuntu 22.04 | 20.04 Linux