ScreenshotNeo

BlogHow-to

How to Add a Delay Before CaptureKit Screenshots a JavaScript-Heavy Page

Add a fixed wait to CaptureKit screenshots, then choose a navigation or element-based wait when a JavaScript-heavy page needs a specific ready signal.

By the ScreenshotNeo team4 October 20266 min read

To make CaptureKit wait before taking a screenshot, add the delay query parameter to its /v1/capture request. The value is in seconds, from 0 to 10, and defaults to 0. For example, delay=2 adds a two-second fixed wait. [CaptureKit endpoint reference]

A delay can give JavaScript-heavy content extra time to settle, but it does not detect when the page is actually ready. If the page has a reliable navigation milestone or a specific element that signals readiness, consider wait_until or wait_for_selector, respectively. You can also combine a condition-based wait with a delay.

1. Add a fixed delay to a CaptureKit request

CaptureKit uses a GET request to https://api.capturekit.dev/v1/capture. Pass the target page as the url query parameter, add delay, and send your API key in the x-api-key header. The API key is managed in the dashboard’s API Keys area; keep it private. [CaptureKit API introduction]

GET https://api.capturekit.dev/v1/capture?url=https%3A%2F%2Fexample.com&delay=2
x-api-key: YOUR_API_KEY

URL-encode the target page when building the request. A command-line client or HTTP library can usually do this for you.

cURL

curl -G 'https://api.capturekit.dev/v1/capture' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-urlencode 'url=https://example.com' \
  --data-urlencode 'delay=2' \
  --output screenshot.png

Python

import os
import requests

api_key = os.environ['CAPTUREKIT_API_KEY']
response = requests.get(
    'https://api.capturekit.dev/v1/capture',
    headers={'x-api-key': api_key},
    params={'url': 'https://example.com', 'delay': 2},
    timeout=90,
)
response.raise_for_status()
with open('screenshot.png', 'wb') as image_file:
    image_file.write(response.content)

Set CAPTUREKIT_API_KEY in your environment before running the script. The example assumes the endpoint returns image bytes for a successful capture.

Node.js

const apiKey = process.env.CAPTUREKIT_API_KEY;
if (!apiKey) throw new Error('Set CAPTUREKIT_API_KEY first');

const query = new URLSearchParams({
  url: 'https://example.com',
  delay: '2',
});
const response = await fetch(
  `https://api.capturekit.dev/v1/capture?${query}`,
  { headers: { 'x-api-key': apiKey } },
);
if (!response.ok) {
  throw new Error(`CaptureKit returned ${response.status}: ${await response.text()}`);
}
const bytes = new Uint8Array(await response.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('screenshot.png', bytes));

Save the response using the format and response behavior configured for your CaptureKit account or endpoint. The example uses a PNG filename for a typical screenshot response.

2. Choose between delay and readiness conditions

Option What triggers capture When it can help
delay A fixed number of seconds after the relevant page load handling. When you know the page needs a small, predictable settling interval.
wait_until A documented navigation condition: domcontentloaded, load, networkidle0, or networkidle2. When a navigation milestone is a useful signal for the page.
wait_for_selector The specified page element appears. When a known element indicates that the content you need has rendered.

These options describe different triggers; the documentation does not give comparative reliability guarantees. A navigation condition may not mean that a single-page app has finished rendering its data, while a selector may be a better signal if the app exposes a stable element. A fixed delay is simple, but it always waits the chosen duration, even when content is ready sooner. [CaptureKit endpoint reference]

Example: combine a navigation wait and delay

CaptureKit’s monitoring article shows wait_until=networkidle2 with delay=2 in an example. Treat that as a configuration to adapt to your target, not a guarantee that every JavaScript application will be ready after two seconds. [CaptureKit monitoring example]

curl -G 'https://api.capturekit.dev/v1/capture' \
  -H 'x-api-key: YOUR_API_KEY' \
  --data-urlencode 'url=https://example.com' \
  --data-urlencode 'wait_until=networkidle2' \
  --data-urlencode 'delay=2' \
  --output screenshot.png

For a selector-based wait, pass the selector documented by the endpoint for wait_for_selector. For example, use the page’s stable results container or a known chart element, rather than a decorative element that appears before its contents are populated. Check the endpoint reference for the accepted parameter format and any selector-specific behavior.

3. Set the delay based on the page

  1. Start with the default behavior or a short delay such as 2 seconds if you have observed a consistent rendering lag.
  2. Capture the same page more than once and inspect whether the required content is present. A single successful capture does not prove the delay is sufficient across different page states.
  3. If the page has a stable ready element, use wait_for_selector as the readiness signal. If navigation completion is the relevant milestone, select an appropriate wait_until condition.
  4. Keep the delay within the documented range of 0–10 seconds. The default is 0.

There is no universal delay for a JavaScript-heavy page: rendering depends on the page and its current state. Treat the value as a page-specific setting and verify the captured output.

4. Troubleshooting

Symptom Likely cause What to try
The screenshot still shows a loading state. The chosen fixed delay was shorter than the page’s rendering time, or the app loads content after its initial navigation. Use a stable wait_for_selector if available, or increase the delay within the documented maximum of 10 seconds. Inspect captures across repeated runs.
The request fails authentication. The API key is missing, invalid, or sent under the wrong header. Send the key as x-api-key and verify it in the CaptureKit dashboard’s API Keys area.
The API rejects the delay value. The value is outside the documented range or is not being passed as a query parameter. Pass delay as a number of seconds from 0 through 10.
The request targets the wrong page or behaves differently than expected. The target URL was not encoded correctly while assembling the query string. Use a URL query builder, such as curl --data-urlencode, Python params, or JavaScript URLSearchParams.
networkidle2 does not correspond to the content being ready. A navigation milestone and application-level readiness are different signals. Wait for a page-specific selector when possible; use a delay as an additional settling interval if needed.

5. Performance, reliability, and cost

A fixed delay adds the selected amount of waiting to each capture, so longer delays can increase request latency and reduce throughput when many captures run in sequence. A condition-based wait can avoid waiting for a full fixed interval when its condition is reached earlier, but its usefulness depends on choosing a condition that matches the page. The researched CaptureKit documentation does not provide timing benchmarks or cost effects for these settings, so check your plan and endpoint behavior before estimating production throughput or charges.

For reliability, use the narrowest stable signal that means the content you need is available, and monitor the returned screenshots for missing content. Do not assume that the same delay works for every route, user state, or runtime condition.

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-request API can return a screenshot; see the ScreenshotNeo API documentation for request options.

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

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and each response says which outcome occurred in its X-Page-Verdict and X-Billed headers. Its MCP server gives AI agents tools named take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month, with no card required.

FAQ

What is CaptureKit’s default delay?

The documented default is 0 seconds. [Endpoint reference]

Can I set a delay longer than 10 seconds?

The documented range is 0–10 seconds. The reference does not document a larger value for this parameter.

Does a two-second delay guarantee that JavaScript has finished?

No. It waits a fixed duration; it does not verify application readiness. Use a selector or navigation condition when that provides a more meaningful signal.

Where does the CaptureKit API key go?

Send it in the x-api-key request header. Keep it out of public client-side code. [API introduction]