Node.js Screenshot API code sample

We have provided an npm package for easy use:

https://www.npmjs.com/package/screenshotapi

Install dependencies

npm install screenshotapi --save

const API_KEY = 'YOUR API KEY GOES HERE';

var ScreenshotApi = require('screenshotapi');

var captureRequest = {
  url: 'http://www.amazon.com',
  webdriver: 'firefox',
  viewport: '1280x1024',
  fullpage: false,
  javascript: true
};

ScreenshotApi.getScreenshot(
  API_KEY,        // your api key
  captureRequest, // the site to capture and your settings
  './'            // local path to store the screenshot png
  )
  .then( (localFile) => {
    console.log(`Downloaded to ${localFile}`);
  })
  .catch( (err) => {
    console.error('Error capturing screenshot:', err);
  });