https://www.bleepingcomputer.com/news/software/chrome-and-firefox-can-take-screenshots-of-sites-from-the-command-line/

Chrome and Firefox Can Take Screenshots of Sites From the Command Line

By

Both Chrome and Firefox have the ability to take screenshots of web sites directly from the command line. This allows you to create scripts or scheduled tasks that automatically take screenshots of web sites at various intervals.

When using this feature, the browsers will be started in a headless mode, which means the browser will not become visible to the user and will close after performing the desired request. Headless mode makes it ideal when using this feature during scripted tasks as the browser windows will not appear and interrupt other tasks you are working on.

Taking screenshots from the command line using Chrome

Using Chrome, you can take a screenshot of the first screen of visible content of a web page using the following command:

"[path_to_chrome]" --headless --screenshot="[path_to]\image.png" "[url]"

When capturing screenshots using Chrome in Windows, if you leave out the path where you wish to save the image, it will try and save the screenshot to the Chrome folder under C:\ProgramFiles  (x86). This will cause it to fail as users do not have permission to create files in that folder.

Instead you should specify the full path to where you wish to save the screenshot as shown in the example below.

"c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="D:\test\chrome.png" "https://www.bleepingcomputer.com/"

Taking a screenshot with Chrome is illustrated in the image below.

Taking screenshots from the command line in Chrome
Taking screenshots from the command line in Chrome

When taking screenshots using the above command, it will only make an image of a portion of the requested web page. If you wish to create a screenshot of the entire web page, you can use the –window-size=width,height argument as shown below.

To make sure you capture the full page, it is recommended to utilize a width and height greater than the existing page.

"c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="d:\test\chrome.png" --window-size=1024,2550 "https://www.bleepingcomputer.com/"

After using the above command, your screenshot will look similar to the image below.

Full Page Chrome Screenshot

Full Page Chrome Screenshot

When creating screenshots, Chrome will show the scrollbars. To remove the scrollbars you can add the –hide-scrollbars argument to the command like below.

"c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="d:\test\chrome.png" --hide-scrollbars --window-size=1024,2550 "https://www.bleepingcomputer.com/"

Taking screenshots from the command line in Firefox

Firefox also has the ability to take screenshots from the command line. The advantage to using Firefox for this task is that it defaults to taking full screen images automatically so you do not have to fiddle with the width and the height of the screenshot.

Full Page Chrome Screenshot

When creating screenshots, Chrome will show the scrollbars. To remove the scrollbars you can add the –hide-scrollbars argument to the command like below.

"c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --screenshot="d:\test\chrome.png" --hide-scrollbars --window-size=1024,2550 "https://www.bleepingcomputer.com/"

Taking screenshots from the command line in Firefox

Firefox also has the ability to take screenshots from the command line. The advantage to using Firefox for this task is that it defaults to taking full screen images automatically so you do not have to fiddle with the width and the height of the screenshot.

To take a screenshot from the command line in Firefox, you would use the following command:

"[path_to_firefox" --screenshot [url]

For example in Windows, to take a screenshot of BleepingComputer.com from the command line you would use the following command, which saves the file to the directory where the command was executed.

"c:\Program Files\Mozilla Firefox\firefox.exe" --screenshot https://www.bleepingcomputer.com/

How the command works is illustrated in the image below.

Taking a screenshot from the command line

When a screenshot is created it will be named screenshot.png and by default contains a full screen image of the entire requested web page.

Screenshot of BleepingComputer.com