How to Capture a Website After JavaScript Finishes Loading with ScreenshotMachine
Use ScreenshotMachine’s delay parameter to give JavaScript-rendered pages time to load, then check the result and adjust the wait if needed.
To capture a JavaScript-rendered page with ScreenshotMachine, set its delay parameter to wait before the screenshot is created. Start with 2000 milliseconds, inspect the result, and increase the delay if content is still missing. This is a fixed timer: ScreenshotMachine’s documented API does not say that it detects JavaScript completion, waits for network idle, or waits for a particular element.
For example, request https://api.screenshotmachine.com/ with your customer key, target url, and delay=2000. The service returns an image response. Use the vendor’s API documentation for current account and parameter details.
1. Set a delay in the ScreenshotMachine API
ScreenshotMachine documents a default delay of 200 ms and supported values of 0, 200, 400, 600, 800, 1000, then each 1,000 ms increment from 2000 through 10000. A longer wait gives client-side code more time to render, but it does not guarantee that a slow or stalled page will be ready.
Replace YOUR_KEY and the example URL with your account key and target. The documentation’s example uses a 2,000 ms delay:
curl -Gs 'https://api.screenshotmachine.com/' \
--data-urlencode 'key=YOUR_KEY' \
--data-urlencode 'url=https://example.com/app' \
--data-urlencode 'delay=2000' \
--output screenshot.png
URL-encode query values. This matters for target URLs with query strings, fragments, or other reserved characters. ScreenshotMachine specifically calls out reserved characters such as # in selectors.
Python
This example uses the requests package and writes the response body to a file:
import requests
params = {
"key": "YOUR_KEY",
"url": "https://example.com/app",
"delay": 2000,
}
response = requests.get(
"https://api.screenshotmachine.com/",
params=params,
timeout=90,
)
response.raise_for_status()
with open("screenshot.png", "wb") as image_file:
image_file.write(response.content)
print("Saved screenshot.png")
Install the dependency with python -m pip install requests. Treat the key as a secret in server-side code and environment configuration; do not commit it to a public repository.
Node.js
This example uses the built-in fetch API available in current Node.js releases. It checks the HTTP response before saving the image:
import { writeFile } from "node:fs/promises";
const params = new URLSearchParams({
key: "YOUR_KEY",
url: "https://example.com/app",
delay: "2000",
});
const response = await fetch(
`https://api.screenshotmachine.com/?${params}`
);
if (!response.ok) {
throw new Error(`Screenshot request failed: HTTP ${response.status}`);
}
await writeFile("screenshot.png", Buffer.from(await response.arrayBuffer()));
console.log("Saved screenshot.png");
As with Python, keep the key on a server you control rather than exposing it in browser JavaScript.
2. Choose the capture size and device
Set dimensions and device to match the page context you need. ScreenshotMachine documents desktop, phone, and tablet device values. Its dimensions can specify a width and height; for a full-page capture, the documentation gives 1024xfull as an example. Adapt the request like this:
curl -Gs 'https://api.screenshotmachine.com/' \
--data-urlencode 'key=YOUR_KEY' \
--data-urlencode 'url=https://example.com/app' \
--data-urlencode 'delay=2000' \
--data-urlencode 'dimension=1024xfull' \
--data-urlencode 'device=desktop' \
--output full-page.png
Use the dimensions and device controls documented by ScreenshotMachine for the desired viewport. Longer pages may contain more images or animations; the vendor suggests allowing a longer delay, such as 2,000 ms or more. Inspect the output because a fixed timer cannot establish that every resource or animation has finished.
3. Tune the wait by inspecting the image
- Begin with
delay=2000for a client-rendered page. - Open the resulting image and look for loading placeholders, empty data areas, or visibly incomplete content.
- If content is incomplete, retry with a longer supported delay, up to the documented
10000ms value. - For long or animated pages, inspect the full-page result as well as the initial viewport.
- When testing a changing page, set an appropriate cache limit or use
cacheLimit=0to force a fresh screenshot, as documented by ScreenshotMachine.
This process tunes a timer against the page you observe. It cannot guarantee readiness when rendering time varies between requests. The documented ScreenshotMachine API does not provide a JavaScript promise, named-selector readiness, or network-idle wait condition.
4. Handle overlays and focus the capture
A cookie prompt or other overlay can cover the page even when its content has rendered. ScreenshotMachine documents controls for clicking or hiding elements before capture and for narrowing the output to an element or crop:
clickcan click a selected element before the screenshot, such as a consent button.hidecan suppress selected elements, such as an overlay.selectorcan capture a matched DOM element.cropcan limit the image to a rectangle.
These controls change page interaction or framing; the documentation does not describe them as JavaScript-ready checks. URL-encode selector values, especially when they include reserved characters. Check the vendor’s current API documentation for exact parameter syntax and supported values.
5. Check for stale captures and API errors
ScreenshotMachine documents a default cache limit of 14 days. During tests of dynamic content, an older cached result can make a successful request look as if the delay had no effect. Set an appropriate cacheLimit; use cacheLimit=0 when you need to force a fresh screenshot.
When a response is unexpected, check both the saved image and the X-Screenshotmachine-Response header. The documentation lists error codes including invalid_key, missing_url, invalid_url, no_credits, and invalid_selector. An error image may be returned for an invalid or incomplete request, so a file being written does not prove it contains the requested page.
6. Common problems and fixes
| Symptom | Likely cause | What to do |
|---|---|---|
| Screenshot shows a spinner or placeholder | The fixed delay was shorter than the page’s render time. | Increase delay using a supported value and inspect another capture. There is no documented readiness-event wait. |
| Screenshot looks unchanged after increasing delay | A cached screenshot may be reused. | Adjust cacheLimit; set it to 0 to force a fresh capture. |
| Image contains an API error instead of the page | The key, URL, credits, or selector may be invalid. | Read X-Screenshotmachine-Response; correct the relevant input or account issue. |
| Request fails for a URL or selector with special characters | Reserved characters were not encoded correctly. | Use URL-encoding helpers such as curl’s --data-urlencode or Python’s params. |
| Consent dialog hides page content | The page rendered, but an overlay remains on top. | Use the documented click or hide selector controls if appropriate, and verify the selected element matches the page. |
| Full-page image misses lower-page content | Lazy-loaded images, animation, or additional page content needed more time. | Use full-page dimensions and try a longer delay; inspect the resulting image rather than assuming the timer guarantees all content. |
7. Performance, reliability, and cost considerations
A fixed delay adds that wait before each screenshot, so a larger value can increase the time to receive an image even when the page renders quickly. A shorter value reduces waiting but raises the chance that client-side content is incomplete. Tune against representative pages and use the smallest delay that gives the result you need.
Reliability depends on the target page as well as the screenshot request: variable API responses, blocked resources, animations, and stalled scripts can outlast any chosen timer. ScreenshotMachine’s documented delay is not a completion guarantee. For fresh-content checks, account for its documented cache behavior and inspect response headers and image contents.
ScreenshotMachine’s pricing and terms can change. Check its current pricing information before estimating the cost of a workload. Its terms describe the API as provided “as is” and restrict certain uses; review the current terms for your use case.
Or skip the browser setup
ScreenshotNeo provides a one-request screenshot API with a configurable wait for a selector, delay, or network idle. Its clean-shot options accept cookie and consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers say which outcome occurred. An MCP server exposes screenshot tools for Claude, Cursor, and other MCP clients.
Example request (see the ScreenshotNeo API documentation):
curl -G "https://api.screenshotneo.com/v1/shot" \
-d access_key=YOUR_API_KEY \
--data-urlencode url=https://example.com/app \
-o shot.webp
Python:
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com/app"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
Node.js:
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.com/app'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
It includes 1,000 screenshots a month free with no card; paid plans start at $5 for 3,000. Sign up for free and try ScreenshotNeo.
FAQ
Does ScreenshotMachine know when JavaScript has finished?
The documented delay is a timer before capture. The API documentation does not describe JavaScript completion detection, a network-idle condition, or waiting for a specific element.
What delay should I start with?
Try 2,000 ms, the value used in the vendor’s API example, then inspect the image and adjust within the supported values.
Can I capture a full page?
Yes. The documentation gives 1024xfull as a full-page dimension example. Longer pages may need a longer delay, but verify the output.
Why do I see an old version of the page?
The documented default cache limit is 14 days. Set a suitable cache limit or use cacheLimit=0 when you need a fresh capture.
Can I wait for a particular element with ScreenshotMachine?
The dossier’s API documentation describes a fixed delay and selector-based click, hide, and capture controls, but not a selector-readiness wait. A selector capture targets an element for output; it does not establish that JavaScript has finished.


