Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  13] [ 0]  / answers: 1 / hits: 17304  / 3 Years ago, tue, may 18, 2021, 6:23:11

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.


More From » firefox

 Answers
4

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: Screenshotstest.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


[#24331] Wednesday, May 19, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arsleyeuth

Total Points: 72
Total Questions: 121
Total Answers: 112

Location: North Korea
Member since Mon, Oct 31, 2022
2 Years ago
;