How to Wait for JavaScript to Load Before CloudConvert Captures a Webpage
Use CloudConvert’s `wait_for_element` selector to wait for rendered content before capture. Learn what it does, how to configure it, and how to handle jobs reliably.
To wait for JavaScript-rendered content before CloudConvert captures a webpage, set wait_for_element on its capture-website task to a CSS selector that appears when the specific content you need is present. For example, use #results-ready if the page adds that element after loading its results. CloudConvert’s example uses body, but that can match a page shell before its data has rendered. This option waits for the selected element; it is not documented as waiting for all JavaScript, network activity, or every asynchronous component to finish. See the [CloudConvert Website Screenshot API](https://cloudconvert.com/website-screenshot-api) and [capture-website operation documentation](https://cloudconvert.com/api/v2/capture-website).
Configure a readiness selector
Choose a selector whose appearance corresponds to the content you want in the capture. Prefer a results container, completed-state marker, or other page-specific element over a generic selector such as body. The selector must describe an element on the target page; CloudConvert does not document whether it checks DOM presence or visibility, or what happens if the selector never appears.
- Identify a stable CSS selector that appears when the required content is rendered, such as
#results-ready. - Add it as
wait_for_elementto thecapture-websitetask. - Choose an output format supported for your capture. The operation supports format-dependent options; the Website Screenshot API describes PNG and JPG screenshots, and the operation documentation also lists PDF.
- Export the capture with an
export/urltask, then handle job completion separately.
Example job payload
{
"tasks": {
"capture-page": {
"operation": "capture-website",
"url": "https://example.com/page",
"output_format": "png",
"wait_for_element": "#results-ready"
},
"export-capture": {
"operation": "export/url",
"input": "capture-page"
}
}
}
Replace the URL and selector with values for your page. CloudConvert’s example uses body; a more specific selector is appropriate when the page shell renders before the JavaScript-powered content. Do not assume the selector wait also waits for images, animations, or unrelated requests unless the page’s readiness marker is designed to represent those conditions.
Create and collect the CloudConvert job
Submit the job to POST https://api.cloudconvert.com/v2/jobs with authorization for your CloudConvert account. The task needs a URL and output format. The following cURL example creates a PNG capture and requests an export URL. Replace the placeholder with your API key.
curl -X POST "https://api.cloudconvert.com/v2/jobs" \
-H "Authorization: Bearer YOUR_CLOUDCONVERT_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"tasks": {
"capture-page": {
"operation": "capture-website",
"url": "https://example.com/page",
"output_format": "png",
"wait_for_element": "#results-ready"
},
"export-capture": {
"operation": "export/url",
"input": "capture-page"
}
}
}'
CloudConvert’s Jobs API documents that asynchronous job creation returns a job in processing status. Creating the job is not the same as having the image ready: poll or otherwise handle the job’s completion according to the Jobs API, then retrieve the export URL from the completed export task. For long-running jobs, CloudConvert recommends webhooks; its synchronous create-and-wait endpoint is available, but the documentation cautions that long waits can run into network timeouts and queueing delays. Review the [Jobs API](https://cloudconvert.com/api/v2/jobs) for current request and completion details.
Choose a selector that reflects readiness
| Selector approach | When it fits | Limitation |
|---|---|---|
body |
The whole page body is the relevant readiness signal. | Often present before JavaScript data or components have rendered. |
| A results or content container | The capture depends on a particular section, such as a search result list. | The element might appear before its contents are complete; choose a marker that reflects the state you need. |
| A page-specific completion marker | Your application can expose a stable element after the required data is ready. | It only signals the conditions your application associates with that marker. |
A selector is a useful synchronization point when you control the page or can identify a reliable state marker. If a third-party page has no stable marker, the documented behavior does not provide a guarantee that all asynchronous work has finished. Avoid treating a generic element as proof that the page is complete.
Output and capture options
Set output_format for the result you need. CloudConvert’s Website Screenshot API describes PNG and JPG screenshot output, while the capture-website operation documentation includes PDF. Other options vary by format, so consult the operation documentation for the selected output instead of copying image settings into a PDF job or vice versa. The service describes full-page screenshots, viewport and zoom controls, and a headless Chrome browser based on the latest Chrome version for its screenshot capture.
The same page readiness issue applies whichever output you choose: put the selector on the capture task, and make the selector represent the content or state required in that output. The task’s general timeout documentation does not define a separate selector-wait timeout, so do not use it to infer how long wait_for_element waits.
Common problems and fixes
| Symptom | Likely cause | What to check |
|---|---|---|
| The capture contains a shell but not the expected data. | The selector matches an element rendered before the JavaScript data. | Use a more specific content-ready selector, not a generic body selector. |
| The expected selector is not found. | The selector is misspelled, does not match this URL, or the page never creates that element. | Inspect the page’s DOM and confirm the selector exists in the target state. CloudConvert’s inspected documentation does not define the missing-selector failure behavior. |
| The selector appears but some content is still incomplete. | The marker signals only part of the page’s asynchronous work. | Use a marker that your page adds after all capture-critical data is ready. The option is not documented as a general network-idle or all-JavaScript wait. |
| The job is still processing when the client stops waiting. | Job creation is asynchronous, or a synchronous request exceeded the client or network wait window. | Track job status separately and use a webhook for long-running work. Retrieve the export after completion. |
| The output is not the desired file type. | The capture task’s output format or format-specific options do not match the need. | Set the requested format and check the operation documentation for that format’s supported options. |
Performance, reliability, and cost considerations
- Make the readiness signal useful. A precise selector prevents capturing an early page shell, but it cannot promise readiness conditions that the selected element does not represent.
- Handle capture and job completion as separate stages. A created job may still be processing. Webhooks are the documented choice for long-running jobs; a synchronous wait can be affected by network timeouts and queueing.
- Avoid assuming a selector timeout. The reviewed capture documentation does not specify the selector-wait timeout, visibility semantics, or behavior when a selector is absent. The general task timeout is not documented as governing this wait.
- Consider output and retention. Choose image or PDF options based on the downstream use. CloudConvert’s Jobs API says jobs are automatically deleted 24 hours after they end; check current data and retention terms for operational or privacy requirements.
- Check current pricing for your workload. The reviewed sources do not establish a price for this capture configuration, so estimate cost from current CloudConvert pricing and your actual job volume rather than assuming a per-capture rate here.
Or skip the browser setup
[ScreenshotNeo](https://screenshotneo.com) provides a screenshot API and MCP server. Make a GET request with a URL to receive an image or PDF; the [API documentation](https://screenshotneo.com/docs/) lists the available options. For a basic capture:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/page -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.com/page"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.com/page'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
- Cookie banners, popups, and chat widgets are removed before the shot; each cleanup step can be turned off.
- Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Response headers report the page verdict and billing status.
- An MCP server lets AI agents use
take_screenshot,get_page_info, andcapture_pdf. - 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000 screenshots.
Sign up for 1,000 free screenshots a month, with no card required.
FAQ
Does wait_for_element wait for every JavaScript function?
No such guarantee is documented. It waits for a custom CSS selector; choose one tied to the content state you need.
Should I use body?
Use it only when the body itself is a meaningful readiness signal. A page-specific selector is usually more useful when data renders after the shell.
Can I use the same selector setting for a PDF?
The capture operation supports format-dependent options and documents PDF output. Check the operation documentation for the options supported with the format you choose.
How long does CloudConvert wait for the selector?
The inspected documentation does not specify the selector timeout or behavior when the selector does not appear. Do not infer those details from the general task timeout.


