The Google Chrome 59 and newer versions have included a new feature headless which provides functionality to run Google Chrome without UI. This allows users to use Google Chrome on the command line as well as scripts. This headless Google Chrome version also included the feature to capture a screenshot of any website using the command line tool.
Requirements:
You must be using Google Chrome 59 or a later version. With Google Chrome version 59, it’s only available for MAC OS and Linux users. Windows users still have to wait for some time.
Capture Screenshot:
Use the following command to capture a screenshot of the given web page. The output file will be created in the current directory with the name screenshot.png.
google-chrome --headless --disable-gpu --screenshot http://www.example.com/
You can also specifiy the dimension of screenshot using --window-size
option like below.
google-chrome --headless --disable-gpu --window-size=1280,768 --screenshot http://www.example.com/
You can also specify output filename with location as --screenshot=file1.png
to create specific name.
google-chrome --headless --disable-gpu --print-to-pdf=file1.png http://www.example.com/
Reference:
https://developers.google.com/web/updates/2017/04/headless-chrome
4 Comments
Seems no direct way to capture full screen by just the command line.
is it possible to login on some website with username and password than take screenshots ? i am using mac.
There is a slight mistake in last code piece:
google-chrome –headless –disable-gpu –print-to-pdf=file1.png http://www.example.com/
Should be
google-chrome –headless –disable-gpu –screenshot=file1.png http://www.example.com/
The –print-to-pdf option will render to PDF
Thank you Rahul. Can u pls tell me how to take snap of the entire page?