Use a screenshot API from TypeScript by sending an authenticated HTTP request from your server, checking the status code, and writing the successful binary response to a file. The request format is provider-specific. This guide uses ScreenshotEngine for a complete fetch-based example, then shows how its contract differs from other documented services and SDKs.
How do I take a screenshot with an API in TypeScript?
The safest integration pattern is:
- Keep the provider key in a server-side environment variable.
- Send the target URL and capture options in the provider’s documented format.
- Check
response.ok(or the status code) before reading the body as an image. - Write the binary body to disk or return it from your own endpoint.
The following example targets ScreenshotEngine. Its documented endpoint is https://api.screenshotengine.com/v1/screenshot. It expects a bearer token, JSON, and fields such as url, format, and height. A successful response is image bytes; an error response is JSON. Do not reuse this endpoint or body with another provider.
Prerequisites
- Node.js 20 or later, which supplies the built-in
fetchused in this example. - A ScreenshotEngine API key stored as
SCREENSHOTENGINE_API_KEY. - A TypeScript project configured to emit or run server-side code. Never expose the key in browser JavaScript.
Runnable TypeScript example
import { writeFile } from "node:fs/promises";
const apiKey = process.env.SCREENSHOTENGINE_API_KEY;
if (!apiKey) {
throw new Error("Set SCREENSHOTENGINE_API_KEY before running this program");
}
const response = await fetch("https://api.screenshotengine.com/v1/screenshot", {
method: "POST",
headers: {
"Authorization": `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Accept": "image/*, application/json"
},
body: JSON.stringify({
url: "https://example.com",
format: "png",
height: 1200
})
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`ScreenshotEngine ${response.status}: ${errorText}`);
}
const imageBytes = new Uint8Array(await response.arrayBuffer());
await writeFile("example.png", imageBytes);
console.log("Saved example.png");
Run it on the server with your normal TypeScript runner, for example after exporting SCREENSHOTENGINE_API_KEY. The explicit status check matters: attempting to save an error JSON document as a PNG creates a file that appears corrupt but is actually an API error.
How do I call a screenshot API from Node.js?
Node’s built-in fetch is enough for a direct integration. The same ScreenshotEngine request in plain JavaScript is:
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
const { writeFile } = require("node:fs/promises");
const response = await fetch("https://api.screenshotengine.com/v1/screenshot", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SCREENSHOTENGINE_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ url: "https://example.com", format: "jpeg", height: 900 })
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
await writeFile("example.jpg", new Uint8Array(await response.arrayBuffer()));
ScreenshotEngine’s documented sample uses a 120-second client timeout budget. Treat that as an example for your client, not as a promise about API response time. In production, apply your own timeout and cancellation policy so a stalled request does not consume a worker indefinitely.
Adding a timeout with AbortController
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), 120_000);
try {
const response = await fetch("https://api.screenshotengine.com/v1/screenshot", {
method: "POST",
signal: controller.signal,
headers: {
Authorization: `Bearer ${process.env.SCREENSHOTENGINE_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ url: "https://example.com", format: "webp", height: 1000 })
});
if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`);
const bytes = new Uint8Array(await response.arrayBuffer());
// Persist or stream bytes here.
} finally {
clearTimeout(timer);
}
How do I save the screenshot returned by an API?
Use response.arrayBuffer() and convert it to Uint8Array before calling writeFile. This preserves PNG, JPEG, or WebP bytes. If your application is an HTTP route, stream or return the bytes instead of writing a temporary file:
const bytes = new Uint8Array(await response.arrayBuffer());
return new Response(bytes, {
headers: {
"Content-Type": response.headers.get("content-type") ?? "image/png",
"Cache-Control": "no-store"
}
});
Some services do not return bytes directly. The Screenshot API REST reference documents GET and POST behavior in which a request can produce JSON or a redirect, along with bearer authentication and additional header options. Inspect that provider’s current response contract and branch on Content-Type before deciding whether to call arrayBuffer(), json(), or follow a URL. A response shape is not a cross-provider standard.
Using cURL, Python, and Node.js with ScreenshotEngine
These examples use the same provider and fields as the TypeScript sample. Replace the target URL and output extension when you change format.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →cURL
curl -X POST "https://api.screenshotengine.com/v1/screenshot"
-H "Authorization: Bearer $SCREENSHOTENGINE_API_KEY"
-H "Content-Type: application/json"
-d '{"url":"https://example.com","format":"png","height":1200}'
-o example.png
Python
import os
import requests
response = requests.post(
"https://api.screenshotengine.com/v1/screenshot",
headers={
"Authorization": f"Bearer {os.environ['SCREENSHOTENGINE_API_KEY']}",
"Content-Type": "application/json",
},
json={"url": "https://example.com", "format": "png", "height": 1200},
timeout=120,
)
response.raise_for_status()
with open("example.png", "wb") as image:
image.write(response.content)
Node.js
const fs = require("node:fs/promises");
const response = await fetch("https://api.screenshotengine.com/v1/screenshot", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.SCREENSHOTENGINE_API_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ url: "https://example.com", format: "png", height: 1200 })
});
if (!response.ok) {
console.error(await response.text());
process.exit(1);
}
await fs.writeFile("example.png", Buffer.from(await response.arrayBuffer()));
Choosing direct HTTP or a TypeScript SDK
| Approach | Best when | Trade-offs |
|---|---|---|
Direct fetch |
You need minimal dependencies, exact control of headers and JSON, or a provider without an SDK. | You must model options, status handling, retries, and response formats yourself. |
| Official SDK | You want typed request objects, convenience methods, or provider-specific error helpers. | Adds a dependency and can hide request details; package APIs can change independently of your code. |
Screenshot API lists a Node package installed with npm install @screenshot-api/js and framework guides for Next.js, Remix, Nuxt, SvelteKit, Storybook, Express, CMS, and commerce projects. ScreenshotOne’s official JavaScript SDK is installed with npm install screenshotone-api-sdk and documents client-based requests, URL generation, download handling, and API error information. ScreenshotMAX documents npm install @screenshotmax/sdk, typed screenshot options, fetching a result, and writing image bytes; its repository also describes PDF, scraping, and scheduled-task capabilities.
Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Use the SDK’s current README for its constructor and option names. Do not combine one vendor’s authentication or parameters with another vendor’s package.
Capture options and provider differences
Before committing to a service, verify these dimensions in its current reference:
- Authentication: ScreenshotEngine’s quickstart uses
Authorization: Bearerand recommends POST for server integrations so the key is not placed in a URL. Screenshot API documents bearer authentication plus other authentication choices. - Transport and response: ScreenshotEngine returns image bytes on HTTP 200 and JSON on errors. Screenshot API documents GET/POST paths that can return JSON or redirects.
- Rendering controls: Check format, viewport or height, full-page behavior, and any wait or device settings before writing integration code.
- Batching: Screenshot API documents a batch endpoint and advanced POST-only settings; availability and field names do not imply support at other vendors.
- SDK fit: Prefer an official package when its types match your framework, but retain explicit status and content-type checks around the result.
Provider documentation establishes feature availability, not independent rankings for speed, reliability, or price. There is no defensible cross-provider performance winner from these references alone.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server for developers. It removes cookie and consent banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and each response identifies the page verdict and billing status in headers. Its MCP tools—take_screenshot, get_page_info, and capture_pdf—let Claude, Cursor, or another MCP client capture pages without you wiring a browser.
The one-call request returns an image or PDF. See the full parameter list in the ScreenshotNeo documentation.
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo supports full-page captures with lazy images loaded, CSS-selector element capture, dark mode, 12 device presets or custom viewports, retina scale, PDF paper settings and page ranges, custom CSS and JavaScript, click and wait actions, ad/tracker/request blocking, headers, cookies, user agents, authorization, timezone and geolocation, transparent backgrounds, resizing, selectable-TTL caching, signed image links, asynchronous webhooks, up to 100 URLs per bulk call, usage reporting, an OpenAPI specification, and familiar parameter names used by other screenshot APIs. Every feature is on every plan: 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
Troubleshooting common failures
The saved image is actually JSON
Cause: The provider returned an error body. Fix: Check response.ok before saving, log the status and text, and inspect the provider’s authentication and validation message.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problems401 or 403 responses
Cause: Missing, malformed, expired, or unauthorized credentials. Fix: Confirm the environment variable is present on the server, send the exact required header, and rotate the key if necessary. Never move it into client-side code or a public query string.
404 or method errors
Cause: An endpoint from one product was paired with another product’s method or path. Fix: Copy the selected provider’s current endpoint and use its documented GET, POST, or batch route.
Timeouts
Cause: The target page or rendering job did not finish within your client budget. Fix: Use an AbortController, avoid unbounded retries, and retry only transient failures with backoff. The 120-second ScreenshotEngine sample is a client example, not a service-level response guarantee.
Blank or incomplete captures
Cause: The page depends on JavaScript, delayed network requests, authentication, or lazy-loaded content. Fix: Use the provider’s documented wait, viewport, cookie, header, or full-page options; verify the target URL independently; and capture after the application reaches its rendered state.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
TypeScript cannot find fetch
Cause: An older Node runtime or TypeScript configuration. Fix: Use Node.js 20 or later for the built-in implementation, or configure a supported fetch implementation explicitly rather than assuming browser globals exist on the server.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Production checklist
- Store keys in secret management or environment variables.
- Validate and allow-list target URLs if users can supply them; unrestricted capture endpoints can be abused to access internal services.
- Set connection and overall timeouts, and limit response sizes before persisting files.
- Log provider, status, duration, target identifier, and error type without logging secrets.
- Handle non-image content types and redirects according to the selected provider’s contract.
- Use deterministic filenames and clean up temporary files.
- Recheck endpoint, SDK, option, and plan documentation before upgrading dependencies or changing providers.
FAQ
Can I call a screenshot API directly from browser TypeScript?
Only when the provider explicitly supports safe public access. Most server integrations should proxy the request through your backend so the API key remains private.
Should I retry every failed screenshot?
No. Retry narrowly classified transient network or service failures with bounded exponential backoff. Do not repeatedly retry authentication, validation, or blocked-target errors.
Is an SDK faster than fetch?
The documented material establishes convenience and typed interfaces, not independent speed benchmarks. Choose based on control, maintenance, and the provider features your application needs.
Recommended Free Tools
How can I return a screenshot from an Express route?
Make the provider request on the server, check its status and content type, then send the resulting bytes with the matching image MIME type. Keep credentials and provider-specific logic outside browser code.
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
Frequently Asked Questions
Can I call a screenshot API directly from browser TypeScript?
Only when the provider explicitly supports safe public access. Most server integrations should proxy the request through your backend so the API key remains private.
Should I retry every failed screenshot?
No. Retry narrowly classified transient network or service failures with bounded exponential backoff. Do not repeatedly retry authentication, validation, or blocked-target errors.
Is an SDK faster than fetch?
The documented material establishes convenience and typed interfaces, not independent speed benchmarks. Choose based on control, maintenance, and the provider features your application needs.
Free tools Windows power users keep installed
One-click scans. No signup required.
How can I return a screenshot from an Express route?
Make the provider request on the server, check its status and content type, then send the resulting bytes with the matching image MIME type. Keep credentials and provider-specific logic outside browser code.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

