Skip to main content
The official screenshotly-js package provides a convenient interface for the Screenshotly API in Node.js.

Installation

npm install screenshotly-js

Setup

const { Screenshotly } = require('screenshotly-js');

// Simple setup
const client = new Screenshotly('your-api-key-here');

// Advanced setup with options
const client = new Screenshotly({
  apiKey: 'your-api-key-here',
  baseUrl: 'https://api.screenshotly.dev', // optional
  timeout: 60000 // optional, in milliseconds
});
Store your API key in an environment variable, not in your source code:
const client = new Screenshotly(process.env.SCREENSHOTLY_API_KEY);

Capture a screenshot

const screenshot = await client.capture({
  url: 'https://example.com',
  width: 1280,
  height: 800,
  format: 'png'
});

if (screenshot.success) {
  console.log('Screenshot URL:', screenshot.data.imageUrl);
  console.log('Remaining credits:', screenshot.remainingCredits);
} else {
  console.error('Error:', screenshot.error);
}

Capture options

ParameterTypeDefaultDescription
urlstringURL to capture (required)
namestringOptional name for the screenshot
widthnumber1920Viewport width in pixels
heightnumber1080Viewport height in pixels
fullPagebooleanfalseCapture the full scrollable page
formatstring'png'Output format: 'png', 'jpeg', 'webp'
deviceScaleFactornumber1Device pixel ratio (2 for retina)
isMobilebooleanfalseEmulate mobile device
hasTouchbooleanfalseEnable touch events
isLandscapebooleanfalseLandscape orientation
waitForSelectorstringCSS selector to wait for
delaynumber0Delay in ms before capture
timeoutnumber30000Request timeout in ms

Batch capture

Capture multiple URLs with shared settings:
const result = await client.captureBatch({
  urls: [
    'https://example.com',
    'https://google.com',
    'https://github.com'
  ],
  options: {
    format: 'png',
    width: 1280,
    height: 800,
    fullPage: true
  }
});

if (result.success) {
  result.data.forEach(item => {
    console.log(`${item.url}: ${item.imageUrl}`);
  });
}

List screenshots

Retrieve your captured screenshots with pagination:
const screenshots = await client.getScreenshots(1, 10); // page 1, 10 per page
console.log('Screenshots:', screenshots.data);

Get a screenshot by ID

const screenshot = await client.getScreenshot('scr_abc123');
console.log('Status:', screenshot.data.status);
console.log('URL:', screenshot.data.screenshotUrl);

Delete a screenshot

const result = await client.deleteScreenshot('scr_abc123');
console.log('Deleted:', result.success);

Error handling

try {
  const screenshot = await client.capture({
    url: 'https://example.com'
  });

  if (!screenshot.success) {
    console.error('Capture failed:', screenshot.error);
  }
} catch (error) {
  // Network errors, timeouts, etc.
  console.error('Request failed:', error.message);
}

Using with ES modules

import { Screenshotly } from 'screenshotly-js';

const client = new Screenshotly(process.env.SCREENSHOTLY_API_KEY);