What is Headless Chrome?
Headless Chrome is like running a chrome browser without UI (browser) i.e., it is running in a headless environment, which is very useful for running automated tests. So, what does headless Chrome unlock for us? One of the most exciting things is the ability to test the latest and greatest web platform features like ES6 modules, service workers, and streams. With headless chrome, you can write apps and test those apps with up-to-date rendering. The other thing that it unlocks is these awesome functionalities like network throttling, device emulation, and code coverage. With headless chrome, you can perform tests without even writing a line of code, isn’t that cool! You can just execute them through the command line. Below are some of the popularly used flags. Note – this is different from the Chromium browser.
Chromium Installation on Ubuntu
Step 1: Update Ubuntu
In the beginning, update the packages in Ubuntu.
Step 2: Install Dependencies
Install these dependencies which are required for the installation. There might be cases where few dependencies would be missing to install chrome. So, run the command below, it will install all the missing dependencies required to install chromium.
Step 3: Download Chrome
Download the google chrome stable package for the Ubuntu system.
Step 4: Install Chrome
Install the stable package.
Step 5: Check Chrome Version
To confirm the installation has finished successfully, check the Google Chrome version.
Optional: Run Chrome Headless
Let me show you an example of running chrome in headless mode. I will run chrome in headless mode, and all the content of https://gf.dev/ will be saved as a pdf file. You can see a file output.pdf Next, I will show you how to do the same setup in the CentOS system.
Chromium Installation on CentOS
Step 1: Update CentOS
Update the CentOS system with the below command.
Step 2: Create Chrome Repository
Add google chrome repository to the system. Create a file google-chrome.repo inside /etc/yum.repos.d/ and add the details below.
Step 3: Install Chrome
Run the yum command below to install the google chrome on the CentOS system.
Step 4: Check Chrome Version
To confirm the installation has finished successfully, check the google chrome version.
Optional: Run Chrome Headless
Let me show you an example of running chrome in headless mode on CentOS. I will take the example of capturing a screenshot. This command below will run chrome in headless mode, and all the content of https://www.chromestatus.com/ will be saved as a pdf file. The output.pdf file got created which has all the content of https://www.chromestatus.com/ That was all about how to install Chrome on Ubuntu & CentOS and run it in the headless mode.