How To Take Screenshot of Website on Linux Command Line
I have worked on a project where websites were migrated from one server to another. Our team clicked with an idea to take screenshot of website before moving and after running it on new server.
This will help us to confirm that website works and looks the same after movement. We can be sure that websites are not broken. For this, we were searching for some tool that can be run from Linux command line to take screenshot of website.
CutyCapt is the one that came to the rescue. It is available in Ubuntu’s repository and is quick to use. Let us see how to use it.
$ sudo apt-get install cutycapt $ cutycapt --url=https://www.apexoutlook.com --out=apexoutlook.png $ file apexoutlook.png apexoutlook.png: PNG image data, 800 x 1919, 8-bit/color RGBA, non-interlaced $ ls -lh apexoutlook.png -rw-rw-r-- 1 himanshug himanshug 263K Jun 29 20:27 apexoutlook.png
By default it renders page in width of 800px and captures the entire height of the webpage. You can see apexoutlook.com is rendered in mobile view instead of desktop view.
To render desktop view, we can specify the width explicitly.
$ cutycapt --min-width=1200px --url=https://www.apexoutlook.com --out=apexoutlook.png
But usually server has no display hardware attached to it and thereby cutycapt throws this error “cannot connect to X server”. To remedy this, there is a virual framebuffer X server.
Install xvfb and xauth to run a virtual X server.
sudo apt-get install xvfb xauth xvfb-run --server-args="-screen 0, 1280x1200x24" cutycapt --url=https://www.apexoutlook.com --out=apexoutlook.png --min-width=1200px
This was the one that helped us in the project. Apart from this, I found that firefox can be used to take screenshot from command line. My primary and favorite browser is Firefox.
$ firefox -screenshot apexoutlook.png https://www.apexoutlook.com
Hope you will find this useful for your projects.
Have a nice day!