An Introduction to Google Chrome Headless Mode – Chrome Tutorial

By | January 28, 2022

In this tutorial, we will introduce what is google chrome headless mode and learn how to use this mode to do some interesting things.

An Introduction to Google Chrome Headless Mode - Chrome Tutorial

What is google chrome headless mode?

Chrome headless mode is very useful for browser automation, it allows us to control chrome to access the internet or get web page using the command line without starting chrome gui. It provides a good way to control google chrome using other application, for example, python script.

How to use the command line to control google chrome

We will use some examples to show you how to use the command line to control google chrom to do some very interesting things in its headless mode.

Example 1: Capture webpage screenshot

goolge-chrome --headless --disable-gpu --screenshot https://www.tutorialexample.com/

In this example, we can find: we can use –headless option to enable chrome headless mode.

Meanwhile, –screenshot will tell chrome create a screenshot for a webpage.

Example 2: convert a webpage to PDF

google-chrome --headless --disable-gpu --print-to-pdf https://www.tutorialexample.com/

Here –print-to-pdf option will tell chrome to convert a webpage to a pdf file.