DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk6 min

How to Use ScreenshotOne in a Next.js App

A practical server-side ScreenshotOne integration for Next.js, with a protected API key, URL validation, binary response handling, SDK guidance, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use ScreenshotOne from server-side code in Next.js: keep the access key in a server-only environment variable, call ScreenshotOne’s HTTPS /take endpoint (or its JavaScript/TypeScript SDK), and return the binary response from a Route Handler. Validate target URLs before fetching them, and handle upstream JSON errors separately from image or PDF data.

Set up the API key and server endpoint

  1. Create or copy an access key from ScreenshotOne’s API keys page. The access key authenticates requests; the separate secret key is used for signing or webhook verification.

    As an Amazon Associate I earn from qualifying purchases.

  2. Store the access key in server-side environment configuration or a secrets manager, such as SCREENSHOTONE_ACCESS_KEY. Do not commit it, put it in a client component, or expose an unsigned request URL containing it. ScreenshotOne’s guidance is to “Treat your API key like a password.”

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  3. Add a Route Handler under the app directory, for example app/api/screenshot/route.ts. The linked Next.js documentation covers version 13 and describes handlers in route.js or route.ts using Request and Response APIs; check the documentation for your installed Next.js version for current runtime details.

  4. Use HTTPS for the request. ScreenshotOne warns that HTTP does not encrypt requests and can expose keys, authorization headers, and cookies in transit.

The following is an illustrative Route Handler pattern. It returns PNG bytes on success and a JSON error on failure. The URL allowlist is intentionally narrow; change it to the destinations your application actually needs.

const allowedHosts = new Set(["example.com", "www.example.com"]);

function validateTarget(value: string | null): URL | null {
  if (!value) return null;

  try {
    const target = new URL(value);
    if (target.protocol !== "https:" || !allowedHosts.has(target.hostname)) {
      return null;
    }
    return target;
  } catch {
    return null;
  }
}

export async function GET(request: Request) {
  const incoming = new URL(request.url);
  const target = validateTarget(incoming.searchParams.get("url"));

  if (!target) {
    return Response.json({ error: "A permitted HTTPS URL is required" }, { status: 400 });
  }

  const accessKey = process.env.SCREENSHOTONE_ACCESS_KEY;
  if (!accessKey) {
    return Response.json({ error: "Screenshot service is not configured" }, { status: 500 });
  }

  const params = new URLSearchParams({
    url: target.toString(),
    access_key: accessKey,
    format: "png",
  });

  let upstream: Response;
  try {
    upstream = await fetch(`https://api.screenshotone.com/take?${params}`);
  } catch {
    return Response.json({ error: "Could not reach the screenshot service" }, { status: 502 });
  }

  if (!upstream.ok) {
    const error = await upstream.json().catch(() => null);
    return Response.json(
      { error: error?.error?.message ?? "Screenshot request failed" },
      { status: upstream.status },
    );
  }

  return new Response(await upstream.arrayBuffer(), {
    headers: {
      "Content-Type": upstream.headers.get("content-type") ?? "image/png",
      "Cache-Control": "no-store",
    },
  });
}

Call the application route from a browser or another server with a URL-encoded target, for example /api/screenshot?url=https%3A%2F%2Fexample.com. Because the access key is added only inside the handler, it is not sent in the browser’s request.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Validate requests and return the right kind of response

A route that accepts arbitrary destinations can be abused to make your server request unintended URLs. Validate the scheme and host, restrict which ScreenshotOne options callers may set, and apply application-level authorization or rate limits where needed. Avoid passing through arbitrary user-supplied headers, cookies, or options.

ScreenshotOne’s API accepts GET and POST. Use POST JSON for large HTML or Markdown inputs instead of placing large values in the query string; the documented maximum POST body size is 100 MiB. The API supports several output formats, including PNG, JPEG, WebP, AVIF, PDF, HTML, and Markdown, depending on the request options. Check the returned content type rather than assuming every successful response is a PNG. Errors are JSON with an error code and message, so do not try to serve an error body as an image.

For pages that require authentication, ScreenshotOne documents passing authorization headers or cookies when you own the site or have permission to access it. Obtaining session cookies may require custom sign-in code. Do not forward a user’s credentials or session cookies without an explicit, secure design.

Use the official JavaScript or TypeScript SDK instead

For a typed client, install ScreenshotOne’s documented package:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
npm install screenshotone-api-sdk

The documented SDK flow creates a Client with access and secret keys, sets the target with TakeOptions.url(...), calls client.take(options), and reads the response as an ArrayBuffer. Recent SDK methods are asynchronous; follow the current package documentation for exact imports and method signatures. For a URL that must be shared, use generateSignedTakeURL() rather than exposing an ordinary unsigned URL with the access key.

See ScreenshotOne’s JavaScript and TypeScript SDK examples and Getting Started guide for the current SDK and request details.

Choose screenshot options deliberately

ScreenshotOne exposes options for capture behavior and output, so keep your public route’s supported set small and document its defaults. Consult the Screenshot Options reference for the current parameter names and supported formats. Common decisions include:

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshoot common failures

Or skip the browser setup

ScreenshotNeo is a screenshot API and MCP server for developers. Its one-call API can return a PNG, JPEG, WebP, or PDF; for this example, save the response as a WebP file. Keep the API key server-side in your Next.js app.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for request options. It removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed; and its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Sign up free for ScreenshotNeo.

Frequently Asked Questions

Can I call ScreenshotOne directly from a Next.js client component?

No. Put the access key and ScreenshotOne request in server-side code, such as a Route Handler, so the key is not exposed to visitors.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can a Next.js route return a PDF instead of an image?

Yes. ScreenshotOne supports PDF output as well as image and other formats; request the needed format and preserve the upstream response content type.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.