To make a screenshot request to the ScreenshotsCloud API use the following format:
https://api.screenshots.cloud/v1/screenshot/[API_KEY]/[TOKEN]/?[PARAMETERS]
Part | Description |
---|---|
API_KEY | Your ScreenshotsCloud API key, to obtain your key sign in to your account. If you do not have an account yet please register. |
TOKEN | The request token is a HMAC SHA1 hash generated from your request parameters and your API Secret. Your ScreenshotsCloud API secret can be obtained by signing in to your account. If you do not have an account yet please register. |
PARAMETERS | A URL query string with screenshot options including the url of the page to be screenshotted. See API Options below for the list. |
API Implementations
We have API implementations already written for you to use in a number of languages. If you have need for an implementation in a language not listed here please contact support@brushd.com.
Install via npm
or GitHub
npm install screenshotscloud
Or if you prefer yarn
yarn add screenshotscloud
Once installed you can generate website screenshot urls as follows:
const ScreenshotsCloud = require('screenshotscloud');
const SCREENSHOTSCLOUD_KEY = 'my-key-generated-at-screenshots-dot-cloud';
const SCREENSHOTSCLOUD_SECRET = 'mysecretstringgeneratedatscreenshotsdotcloud';
const screenshotscloud = ScreenshotsCloud(SCREENSHOTSCLOUD_KEY, SCREENSHOTSCLOUD_SECRET);
const screenshotUrl = screenshotscloud.screenshotUrl({
"url": "openai.com/research",
"width": 800
});
If you wish to download the image the simplest method would be to use a http client such as request
or the built in http
library. Example below:
const ScreenshotsCloud = require('screenshotscloud');
const request = require('request'); // make sure to npm install request or yarn add request to your project first
const fs = require('fs');
const SCREENSHOTSCLOUD_KEY = 'my-key-generated-at-screenshots-dot-cloud';
const SCREENSHOTSCLOUD_SECRET = 'mysecretstringgeneratedatscreenshotsdotcloud';
const screenshotscloud = ScreenshotsCloud(SCREENSHOTSCLOUD_KEY, SCREENSHOTSCLOUD_SECRET);
const screenshotUrl = screenshotscloud.screenshotUrl({
"url": "openai.com/research",
"width": 800
});
request.get(screenshotUrl, {encoding: 'binary'}, function(error, response, imageBody) {
let screenshotResult = imageBody;
// and if you want to save it to disk
fs.writeFileSync('screenshot.png', screenshotResult, 'binary');
});
Parameter | Default | Description |
---|---|---|
url | Required. The website address that you want to take a screenshot of, with or without http:// or https://. | |
browser | fastest | Which browser to run the request on. chrome for Google Chrome, firefox for Mozilla Firefox, fastest to run the request on both browsers and return the request from the browser which renders the screenshot fastest. Defaults to fastest. |
width | 1920 | Width of the thumbnail. We resize from the viewport_width to this width value after the screenshot has been captured. This option is only valid for png or jpg format options. |
viewport_width | 1920 | Width of the browser viewport this is the actual width of the page before we resize it for the thumbnail. |
viewport_height | (1320) | Height of the browser viewport, if you do not give this parameter we will calculate it for you based on viewport_width in 16:10 ratio. |
full_page | false (true if format=pdf) | If true capture a full length screenshot of the requested page. If false capture only the viewport area specified in viewport_width and viewport_height. If the format is pdf this option will always be true. |
format | png | Valid options are jpg, png or pdf. |
quality | 95 (if format=jpg) | Set the jpeg quality of the screenshot if jpg is set as the format. Range from 0-100. |
delay | 100 | Amount of time to wait in milliseconds before taking a screenshot of the page after it is fully loaded. Maximum 60000 (1 minute), minimum 100. |
cache_time | 2592000 | Amount of time in seconds to wait before taking a fresh screenshot for the same request. Maximum 2592000 (30 days), minimum 1. Ignored if force parameter is true. |
force | false | Force a new screenshot to be taken with no cache. |
proxy_address | Route this request through an authenticated or unauthenticated http https or socks external proxy address. e.g. http://myusername:mypassword@my.proxy.address:5959 socks://my.proxy.address:1080 https://username:password@123.123.123.123:443 Currently HTTP/HTTPS requests support authentication but SOCKS5 does not support requests that require authentication. | |
user_agent | Recent Firefox or Chrome User Agent | Set the user agent this screenshot will identify as. Useful for identifying as a mobile or tablet browser or to identify as a specific browser if the website pretends it needs Internet Explorer. |
authorization | ||
trim | false | Trim the excess space around the resulting screenshot using the most top left pixel color, useful for SVG's. |
language | en | Accept-Language header customization for websites that support it, set ja for Japanese, de for German etc. |
cookie | ||
disable_javascript | false | Don't execute javascript on this page. Forces browser=chrome. |
disable_images | false | Don't download images on this page. Forces browser=firefox. |
timeout | 300000 | Amount of time in milliseconds to wait before taking the screenshot anyway. Maximum 300000 (5 minutes). |
mobile | false | Shortcut to set pixel_ratio, user_agent, viewport_width, viewport_height and width to that of the latest iPhone. |
pixel_ratio | 1 | Multiplier that sets the pixel density of the page relative to the resolution, useful for taking retina screenshots (2). |
hide_selector | Accepts valid DOM selector (e.g. .wantedselector). Elements that match the selector you provide will be hidden from view (display: none). | |
click_selector | Accepts valid DOM selector (e.g. .wantedselector[attribute]). Send a click event to all elements matching your selector. | |
hover_selector | Accepts valid DOM selector (e.g. #wantedselector). Mouse will be hovered over the first instance of the selector you specify. Forces browser=chrome. | |
wait_selector | Accepts valid DOM selector (e.g. .valid_selector > .another_class). We will not take the screenshot until .valid_selector appears on this page and is not display:none; or timeout is reached (90 seconds). | |
clip_selector | Accepts valid DOM selector (e.g. .valid_selector:not(div)). Rendered screenshot will only display contents of DOM selector. This option is only valid for png or jpg format options. | |
scroll_selector | Accepts valid DOM selector (e.g. .valid_selector:not(div)). Scroll to DOM element before taking the screenshot. This option is only valid for png or jpg format options. |
These special parameters combined allow you to upload your screenshot request directly to Amazon Web Services S3.
Parameter | Default | Description |
---|---|---|
s3_id | Required Your AWS S3 ID. | |
s3_secret | false | Required Your AWS S3 Secret. |
s3_bucket | Required The bucket your screenshot will be delivered to. | |
s3_path | If other than the root of the bucket specify a different path with this. |
These special parameters when used together allow you to log in to a website before taking the screenshot. The username and password are currently added to the resulting screenshot URL in plaintext (except for our NodeJS implementation which encrypts credentials, this will expand to most implementations in the future) so for security reasons we highly recommend that you download the resulting image and host it on your own service while using this feature.
Parameter | Default | Description |
---|---|---|
login_url | Beta Required for logging in to the website before you screenshot. The url of the website where you can log in e.g. https://www.reddit.com/login. | |
login_username | Beta Required for logging in to the website before you screenshot. E-mail or username required to log in to the website. | |
login_password | Beta Required for logging in to the website before you screenshot. The password used to log in to the website. | |
login_debug | false | Beta If set to true this will produce a screenshot that does not visit to your url so you can see any errors that occured trying to log in. |
If you are downloading the screenshot directly you may find some of our HTTP response headers useful.
Header | Description |
---|---|
Age | The time in seconds this request has been cached, 0 for fresh. |
X-Browser | The browser and browser version that fulfilled the request. |
X-In-Browser-Status | The HTTP Status Code returned by the requested screenshot URL. |
X-In-Browser-Time | The time this request took to render in milliseconds. |
X-Initial-Page-Request-Time | The time this request took to recieve the initial requested page in milliseconds. |
X-Page-Open-Time | The time this request took to reach the onload javascript event in milliseconds. |
X-Processing-Time | The time this request took to process through our complete rendering system in milliseconds. |
If the website of the screenshot you're taking is temporarily unavailable we will send a 400 HTTP error with a JSON encoded object of the error and not cache the request, allowing you to retry the request. If you're displaying the generated screenshot urls directly on your website we'll periodically keep retrying the request until a valid screenshot is available.
Field | Description |
---|---|
error | The ultimate reason we did not complete the request. |
browserError | The reason the browser gave for not completing this request (if any). |
requestParams | The parameters you used to construct this request in object format. |