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?
Well, in Google Chrome and FireFox, apart from the Graphical user interface, headless support is also there out of the box.
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.
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 )
--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:
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
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
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
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
⇒ 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