How to Take WebSite Screenshots from Linux Terminal?

PowerADM.com / Linux / How to Take WebSite Screenshots from Linux Terminal?

If you need to take a screenshot of websites via the Linux server console, you can use the screenshoter (https://github.com/mingalevme/screenshoter). This is an HTTP service in a Docker container based on Google Puppeteer.

In the simplest case, you can start the screenshoter container like this:

# docker pull mingalevme/screenshoter
# docker run -d --restart always -p 8080:8080 --name screenshoter mingalevme/screenshoter

Now, to take a screenshot of the website, it is enough to call the API via HTTP. Just run the curl command in the console:

# curl "http://localhost:8080/screenshot?url=https://poweradm.com" > ~/sitescreen.png

As a result, a site screenshot will be saved to a ~/sitescreen.png file.

You can specify the screen resolution of the client for which you want to create a screenshot:

# curl "http://localhost:8080/screenshot?url=https://poweradm.com&viewport-width=1920&viewport-height=1080" > ~/1920-1080-poweradm_screen.png

This screenshot solution can be used in any webhook-based monitoring system.

screenshoter - docket container to get site screenshot from bash terminal on linux

You can run the Screenshoter container with Nginx to proxy the connection. To do this, use the following docker-compose.yml:

version: "3.1"

services:

 screenshoter-app:
  image: mingalevme/screenshoter
  restart: always

 screenshoter-nginx:
  image: nginx:alpine
  ports:
   - "80:80"
  volumes:
   - ./screenshoter.nginx.conf:/etc/nginx/conf.d/default.conf
   - "/var/log/nginx:/var/log/nginx"
   - "/var/cache/nginx:/var/cache/nginx"
   - "/dev/null:/var/cache/screenshoter"
  depends_on:
   - screenshoter-app

So you can get screenshots of the site directly from a browser.

http://192.168.13.200:8080/screenshot?url=https://poweradm.com&full=true&format=jpeg

The screenshoter has quite a few options. You can specify user-agent, cookies, device-scale-factor, transparency, etc. The full list of screenshoter options is available on the project’s GitHub page.

Leave a Reply

Your email address will not be published. Required fields are marked *