Skip to content

Capture Screenshot

The core functionality of the LaunchBrightly Product Screenshots API is to capture screenshots and as you make this request you have control over what the browser "looks like" and how you want it rendered. Including the ability to pick where you want the output image to be saved (if not just returned as a base64image). You are likely to use have removed elements, taken a set of actions, and perhaps even annotated and styled the image before it is saved to your cloud.

The bare minimum required to take a screenshot

POST /screenshot

Request

json
{
  "url": "https://convertkit.baremetrics.com/stats/arr",
  "elementSelector": [
    ".main-graph",
    ".an_alternate_selector"
  ]
}

The screenshot API allows you to accurately and securely generate screenshots of your web apps at scale.

List of supported attributes

OptionDefault value (if not specified)description
width1200Viewport width
height900Viewport height
userAgentMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36User agent
timeout60000Maximum waiting time (ms) to capture a screenshot
maxRetryCount1No. of times to retry capturing a screenshot. It is disabled by default (when set to 1)
prefersColorSchemelightdark/light mode
cloud.uploads3Save images to Amazon S3 or Cloudflare R2 bucket
cloud.fileObjecte.g /path/acme/light-arr.pngSets the path including file name of your screenshot
deviceScaleFactor2retina
responseTypebase64imagevalues: base64image/queue
acceptLanguageen-USSets an Accept-Language header on requests to the target URL
fullPagefalseCapture a screenshot of the whole page.
captureBeyondViewporttrueCapture the hidden part of the selector (outside of the viewport)
geolocation.latitudenullSets the latitude used to emulate the Geolocation API
geolocation.longitudenullSets the longitude used to emulate the Geolocation API
geolocation.accuracy100Sets the accuracy of the Geolocation API, in metres
stepImages-Allow visual debugging with snapshots of page.
metadata-Add metadata(EXIF) to the captured image. Support up to 5 keys. See example 3.
css.animationsenabledConfigure CSS animation behaviour. Possible values: enabled, disabled and runOnce
css.borderRadiusenabledTweak the border-radius CSS property of the element to screenshot. Possible values: enabled, disabled

Render Options:

width

default: 1280

The viewport width of the browser, in pixels.

height

default: 1280

The viewport height of the browser, in pixels.

userAgent

default: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36

Sets the User-Agent string for the request to avoid bot detection or emulate specific devices.

timeout

default: 60000

The maximum time in milliseconds to wait to capture a screenshot. If the page takes longer to load, the request will mark as failed.

maxRetryCount

default: 1

The number of times to retry capturing a screenshot. It is disabled by default (when set to 1).

prefersColorScheme

default: light

Set the color scheme of the browser. Possible values are light and dark.

acceptLanguage

default: en-US

This parameter sets the browser's language to the specified value. It updates the accept-language HTTP header, as well as the navigator.userLanguage and navigator.language properties, to match the specified language.

Usage

Below is a series of examples demonstrating various properties of the screenshot API endpoint.

Example 1: Sreenshot of a section of page using selector

POST /screenshot

json
{
  "url": "https://convertkit.baremetrics.com/stats/arr",
  "elementSelector": [
    ".main-graph",
    ".container.alternate-selector"
  ],
  "responseType": "queue"
}

Example 2: Screenshot with specific viewport width and height

POST /screenshot

json
{
  "url": "https://convertkit.baremetrics.com/stats/arr",
  "elementSelector": [
    ".main-graph",
    ".container.alternate-selector"
  ],
  "width": 800,
  "height": 400,
  "responseType": "queue"
}

Example 3: Add metadata(EXIF) to the captured screenshot.

POST /screenshot

json
{
  "url": "https://example.org",
  "elementSelector": [
    "body"
  ],
  "metadata": {
    "id": "xxx",
    "description": "Contact form"
  }
}

Success Response

The response will be a JSON object acknowledging your request was received and queued.

Condition: If everything is OK
Code: 202
Example:
json
{
  "id": "6d0fc9ea-acba-4230-a643-db02e6804ebb",
  "createdAt": "2023-04-24T18:50:09.326Z",
  "updatedAt": "2023-04-24T18:50:09.326Z",
  "message": "Your screenshot request has been successfully queued."
}

Error Response(s)

Condition: The elementSelector is invalid or missing
Code: 500
Content Example:
json
{
  "status": "failed",
  "message": "The elementSelector body > div.container > div.container--inner > section > main > section.aux_charts.x,.aux_charts.x is either not present or took too long to render.",
  "createdAt": "2023-06-20T11:55:39.594Z",
  "updatedAt": "2023-06-20T11:57:23.033Z",
  "url": {
    "styled": null,
    "raw": null
  }
}

Selector Priority

Both the fields elementSelector and the steps.[].selectors allows you to specify alternate selectors that lead to the selection of a single element. Specifying alternative selectors helps to improve reliability of the screenshot API as some selectors might get outdated over time.

Currently, we support CSS selectors, ARIA selectors (start with aria/), XPath selectors (start with xpath/).

The Screenshot API looks for selectors in the following order:

  1. ARIA selector if found.
  2. CSS selectors with the following priority:
    1. ID attributes, for example, <div id="invoice">.
    2. Regular CSS selectors.
  3. XPath selectors.

Get capture status

GET /screenshot/:id

Request

Data constraints

A valid :id is required.

Success Response

Condition: If everything is OK
Code: 200
Content Example:
json
{
  "status": "completed",
  "message": "Your screenshot has been generated successfully",
  "createdAt": "2023-05-30T08:36:58.787Z",
  "updatedAt": "2023-05-30T08:37:13.629Z",
  "url": {
    "raw": "https://s3.us-east-1.amazonaws.com/2023-05-30/68dae252-4736-4e65-bb08-44824c2994c4.png",
    "styled": "https://s3.us-east-1.amazonaws.com/2023-05-30/68dae252-4736-4e65-bb08-44824c2994c4_styled.png"
  }
}

The different status values are:

statusDescription
pendingThe screenshot capture request is queued
completedThe screenshot capture completed successfully and available to download in url
failedThe screenshot capture failed. Refer to message for failure reason.

Capture screenshots in bulk

We provide dedicated endpoints for capturing screenshots in bulk. Please send your payload as an array of objects.

POST /screenshot/bulk

Request

json
[
  {
    "url": "https://convertkit.baremetrics.com/stats/arr",
    "responseType": "queue",
    "elementSelector": [
      ".main-graph"
    ]
  },
  {
    "url": "https://convertkit.baremetrics.com/stats/arr",
    "responseType": "queue",
    "elementSelector": [
      "body > div.container > div.container--inner > section > main > section > div.metric-stat > div > h1"
    ]
  }
]

Response

json
{
  "id": "d1f024d4-bd73-437e-8cbc-d10b798590fe",
  "screenshot": [
    {
      "id": "56b01328-5538-43be-9e66-809b7345e505",
      "createdAt": "2024-09-18T12:02:23.186Z",
      "updatedAt": "2024-09-18T12:02:23.186Z"
    },
    {
      "id": "2a21c140-a7fb-49bf-bee6-9b8595f770f7",
      "createdAt": "2024-09-18T12:02:23.188Z",
      "updatedAt": "2024-09-18T12:02:23.188Z"
    }
  ]
}

Get capture status in bulk

POST /screenshot/bulk/:id

Response

json
{
  "summary": {
    "total": 2,
    "success": 2,
    "pending": 0,
    "failed": 0
  },
  "screenshots": [
    {
      "id": "2a21c140-a7fb-49bf-bee6-9b8595f770f7",
      "jobId": "d1f024d4-bd73-437e-8cbc-d10b798590fe",
      "status": "completed",
      "message": "Your screenshot has been generated successfully",
      "warnings": [],
      "createdAt": "2024-09-18T12:02:23.188Z",
      "updatedAt": "2024-09-18T12:02:34.070Z",
      "retryCount": 1,
      "filesize": {
        "raw": 7645,
        "styled": null
      },
      "url": {
        "raw": "https://lb-api-screenshots.s3.us-east-1.amazonaws.com/Dev_Hyder/2024-09-18/raw-2a21c140-a7fb-49bf-bee6-9b8595f770f7.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASH5PNXSCN5O7E7U2%2F20240918%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240918T120249Z&X-Amz-Expires=86400&X-Amz-Signature=270a701466a0be6c5edaa04c2e3b74223a959862468cd69ba18890cf45361169&X-Amz-SignedHeaders=host&x-id=GetObject",
        "styled": null
      },
      "hash": {
        "raw": "de597dc902659ba685c6400f6785d71844b82a04261fedfa77534beaf4db2fd1",
        "styled": null
      },
      "raw": {
        "filesize": 7645,
        "url": "https://lb-api-screenshots.s3.us-east-1.amazonaws.com/Dev_Hyder/2024-09-18/raw-2a21c140-a7fb-49bf-bee6-9b8595f770f7.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASH5PNXSCN5O7E7U2%2F20240918%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240918T120249Z&X-Amz-Expires=86400&X-Amz-Signature=270a701466a0be6c5edaa04c2e3b74223a959862468cd69ba18890cf45361169&X-Amz-SignedHeaders=host&x-id=GetObject",
        "hash": "de597dc902659ba685c6400f6785d71844b82a04261fedfa77534beaf4db2fd1"
      },
      "styled": {
        "filesize": null,
        "url": null,
        "hash": null
      }
    },
    {
      "id": "56b01328-5538-43be-9e66-809b7345e505",
      "jobId": "d1f024d4-bd73-437e-8cbc-d10b798590fe",
      "status": "completed",
      "message": "Your screenshot has been generated successfully",
      "warnings": [],
      "createdAt": "2024-09-18T12:02:23.186Z",
      "updatedAt": "2024-09-18T12:02:35.507Z",
      "retryCount": 1,
      "filesize": {
        "raw": 89701,
        "styled": null
      },
      "url": {
        "raw": "https://lb-api-screenshots.s3.us-east-1.amazonaws.com/Dev_Hyder/2024-09-18/raw-56b01328-5538-43be-9e66-809b7345e505.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASH5PNXSCN5O7E7U2%2F20240918%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240918T120249Z&X-Amz-Expires=86400&X-Amz-Signature=518004705267d51e2c327c11eeab2ccb29b14dc93f9af5bc532b655287fb6e2e&X-Amz-SignedHeaders=host&x-id=GetObject",
        "styled": null
      },
      "hash": {
        "raw": "3244cf8fa645fc760462a60a759372b6b623031f231f9d94482733583fcedad0",
        "styled": null
      },
      "raw": {
        "filesize": 89701,
        "url": "https://lb-api-screenshots.s3.us-east-1.amazonaws.com/Dev_Hyder/2024-09-18/raw-56b01328-5538-43be-9e66-809b7345e505.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIASH5PNXSCN5O7E7U2%2F20240918%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20240918T120249Z&X-Amz-Expires=86400&X-Amz-Signature=518004705267d51e2c327c11eeab2ccb29b14dc93f9af5bc532b655287fb6e2e&X-Amz-SignedHeaders=host&x-id=GetObject",
        "hash": "3244cf8fa645fc760462a60a759372b6b623031f231f9d94482733583fcedad0"
      },
      "styled": {
        "filesize": null,
        "url": null,
        "hash": null
      }
    }
  ]
}

Limitation of Bulk endpoints

The bulk endpoints allow you to submit up to 100 screenshot capture jobs in a single request. If you have more than 100 jobs, you will need to send multiple API requests.

To check the progress of multiple job IDs, separate them with commas, as shown below:

GET /screenshot/bulk/:jobId1,:jobId2,:jobId3