Skip to content
Power On Labs

Small web-data tools, and the runs that show what they return.

How do I take a screenshot of a web page from code?

Send the URL, get one row back per URL with a link to the image file. What makes the difference between a useful screenshot and a useless one is not the capture — it is everything that has to happen before it: scroll the page so lazy-loaded images actually load, get the cookie banner out of the shot, block the ad slots that would otherwise be a grey box.

Running a real browser is what makes those possible, and it is also why a screenshot API costs more than an HTTP fetch.

A real run

Input
{
  "urls": ["https://nodejs.org"],
  "device": "desktop",
  "fullPage": true,
  "format": "png",
  "dismissCookieBanners": "hide",
  "blockAds": true
}
Output — one row per URL (the signed file link is shortened here)
{
  "url": "https://nodejs.org",
  "finalUrl": "https://nodejs.org/en",
  "ok": true,
  "statusCode": 200,
  "title": "Node.js — Run JavaScript Everywhere",
  "format": "png",
  "width": 1920,
  "height": 1080,
  "pageHeight": 1080,
  "truncated": false,
  "bytes": 309031,
  "device": "desktop",
  "scaleFactor": 1,
  "durationMs": 1574,
  "error": null,
  "key": "001-nodejs.org.png",
  "fileUrl": "https://api.apify.com/v2/key-value-stores/.../records/001-nodejs.org.png?signature=...",
  "attempts": 1
}
Full-page screenshot of nodejs.org captured at 1920 by 1080 pixels
The file that run produced, unedited. 1920×1080, 309,031 bytes — on this page the measured full height came out equal to the 1080-pixel viewport, which is why a full-page capture is exactly one screen tall.

The row is meant to be read by a program, so it carries the things a program has to branch on: finalUrl after redirects, the HTTP status, whether it worked, the real pixel size, the bytes, and — when a page is taller than the maximum capture — pageHeight and truncated, so a cut image announces itself instead of looking complete.

The things you will need sooner or later

What you wantHow
Just the visible framefullPage: false — captures the viewport only
An exact frame sizedevice: "custom" with width and height
One element, cropped to itselfselector: "table.infobox" — any CSS selector
What a phone seesdevice: "mobile" — mobile viewport, user agent and pixel density
RetinascaleFactor: 2
The dark themedarkMode: true — the page renders as it does for a visitor who prefers dark
A page behind a loginsession cookies, an extra headers entry, or HTTP Basic auth — all stored encrypted
A whole list at onceput every URL in urls and raise concurrency

What this does not do

What it costs

$0.01 per successful capture. A URL that fails — DNS, timeout, a page that never loads — is not charged, even though it consumed browser time on our side. That is the trade we chose: you should not pay for an image you did not get.

The tool that does it

Website Screenshot & PDF Generator API on Apify Store.

$0.01 per successful capture. No start fee, no subscription. A URL that fails is not charged.