How can I use firefox to take full page screenshots from command line? [duplicate]

I need to take a screenshot of a whole web page.

I have seen How can I take a full page screenshot of a webpage from the command line? where many ways to take a screenshot are proposed but I need to use firefox for a better effect.


Solution 1:

To make screenshots of web pages showing the whole scrollable area of the page in firefox, I propose two separate ways.

Both save an image of the page that shows all parts or the web page that you could reach by scrolling down (and right/left) - think all view positions stitched together;
For long pages, the image can easily be several thousand pixel high.


The "professional" way - using a web browser GUI-level testing and automation tool:

The automation tool Selenium - usually used for UI testing - can do full page screen shots;
It seems to be some overhead to set it up just for that task, though.

For example:

Command: open; Target: http://www.google.com
Command: captureEntirePageScreenshotAndWait; Target: \\Screenshots\\test.png

See so.SE: Screenshots using Selenium IDE Firefox plugin

To install the firefox part of Selenium, get the firefox add-on - but not from the official add-ons page - it's on the download page of Selenium as an xpi file. This is the current version.

(There are lots of add-ons for extending selenium itself (but in the technical for of a firefox add-on), all called "Selenium ..." or even "Selenium IDE ..." on the Add-ons website - very confusing.)


The "hackish" way - using internal firefox commands by keyboard automation:

There is an internal command prompt in firefox, kind of a development tool, which, as @Fireflight pointed out, has a command to make screenshots. But, as far as I know, that can not controlled from the command shell line normally. But what we can do, is to simulate key presses to make use of it.

We need to choose a browser window, open the prompt, enter the firefox internal command (using a file name based on current date and time), run the command, and close the prompt again:

FF=$(xdotool selectwindow)
xdotool key --window $FF Shift+F2 sleep 1
xdotool type --window $FF --delay 50 "screenshot page-$(date +%Y%m%d-%H%M%S).png --fullpage "
xdotool key --window $FF Return sleep 0.5 key --window $FF Shift+F2

The command line utility xdotool can interact with X windows on the level of X11 events. We use it to choose the firefox window that shows the page, and to send the right key strokes to make the screenshot.

(This is a somewhat brittle approach: it's depending on keyboard timing, it will not work if the prompt is already opened, or contains text (To open or close it, press Shift-F2) - but if it works, it's really nice.)


As an example how this kind of screenshot looks, here's an example of man xdotool on manpages.ubuntu.com, scaled down to 20% (original 1336x15653), done with the xdotool solution:

full page screenshot of man xdotool at 20% scale, edited to half hight

Solution 2:

In Firefox you can hit Shift-F2, then in the command line that appears, just type:

screenshot filename.png --fullpage

There are several more commands and options available as well.