A synchronous HTTP screenshot service built on Sinatra and headless Chrome (via Ferrum).
Trigger a screenshot by making a GET
request to /screenshot
with a url
querystring parameter. The endpoint is protected by basic HTTP authentication with your AUTH_TOKEN
.
$ curl "http://[email protected]/screenshot?url=http://example.com" > screenshot.png
Pass options via querystring parameters. A more complicated Screamshot URL might be the following combination of available options:
http://[email protected]/screenshot?url=http://example.com&viewport=800,600&full=true&scale=2&prefers-reduced-motion=reduce
The URL to capture. The only required parameter.
url=http://example.com
Control the size of the viewport with WIDTH,HEIGHT
. Defaults to 1024,768
.
viewport=800,600
Capture the entire page instead of just the viewport. Defaults to false
.
full=true
This mimics devicePixelRatio
and scales the viewport so scale=2
combined with viewport=800,600
results in a 1600×1200 image. Defaults to 1
.
scale=2
Force the browser into prefers-reduced-motion=reduce
mode. This can be used as a standards-based hint to the page not to use animations. Defaults to nothing and so is not enabled.
prefers-reduced-motion=reduce
Deploying to Fly.io
Clone this repository and use flyctl
to create and configure the app (say yes when asked whether you'd like to copy its configuration):
$ fly launch --name my-app-name
Start the server with bundle exec puma -C config/puma.rb
.
Run the tests with bundle exec rspec
.
Write usage docs here, update the homepage with bin/update_docs
.
Copyright © Ben Pickles, MIT licence.