Get started with Screenshot API in minutes. This guide will walk you through the basics of using our API to capture web content.

Installation

First, install our official client library using npm:

bash
01npm install @screenshot/client

Or using yarn:

bash
01yarn add @screenshot/client

Authentication

Get your API key from the Dashboard. We'll use this to authenticate your requests:

javascript
01import { ScreenshotClient } from '@screenshot/client';
02
03const client = new ScreenshotClient('your_api_key');

Basic Usage

Capture a Screenshot

Here's a simple example to capture a screenshot:

javascript
01const screenshot = await client.capture({
02 url: 'https://example.com',
03 captureType: 'screenshot',
04 format: 'png',
05 deviceType: 'desktop'
06});
07
08console.log(screenshot.url); // https://cdn.screenshotapi.io/captures/abc123.png

Extract HTML Content

Extract the HTML content from a webpage:

javascript
01const content = await client.capture({
02 url: 'https://example.com',
03 captureType: 'html',
04 format: 'html',
05 selector: '#main-content'
06});
07
08console.log(content.html);

Retrieve a Favicon

Get a website's favicon:

javascript
01const favicon = await client.capture({
02 url: 'https://example.com',
03 captureType: 'favicon',
04 format: 'png'
05});
06
07console.log(favicon.url);

Advanced Options

Custom Viewport Size

Specify custom dimensions for your captures:

javascript
01const screenshot = await client.capture({
02 url: 'https://example.com',
03 captureType: 'screenshot',
04 width: 1920,
05 height: 1080,
06 deviceType: 'desktop'
07});

Wait for Dynamic Content

Wait for dynamic content to load before capturing:

javascript
01const screenshot = await client.capture({
02 url: 'https://example.com',
03 captureType: 'screenshot',
04 waitDuration: 5 // Wait 5 seconds
05});

Remove Advertisements

Automatically remove ads from captures:

javascript
01const screenshot = await client.capture({
02 url: 'https://example.com',
03 captureType: 'screenshot',
04 removeAds: true
05});

Error Handling

The API uses standard HTTP response codes. Here's how to handle errors:

javascript
01try {
02 const screenshot = await client.capture({
03 url: 'https://example.com',
04 captureType: 'screenshot'
05 });
06} catch (error) {
07 if (error.status === 429) {
08 console.error('Rate limit exceeded');
09 } else {
10 console.error('Capture failed:', error.message);
11 }
12}

Next Steps

Ready to Get Started?

Get your API key now and start capturing screenshots in minutes.