- Docs
- Parameters
- max_wait_ms
max_wait_ms
Limit how long the API waits before capturing your image
How it works
Section titled “How it works”The max_wait_ms parameter sets a maximum time limit for waiting before the screenshot is taken. This is useful when pages load extra irrelevant content that you don’t need to wait for.
Value range
Section titled “Value range”| Minimum | Maximum |
|---|---|
500 ms |
10000 ms (10 seconds) |
max_wait_ms vs ms_delay
Section titled “max_wait_ms vs ms_delay”These two parameters serve different purposes:
| Parameter | Purpose | Behavior |
|---|---|---|
ms_delay |
Add extra wait time | Waits for the specified time after the page loads |
max_wait_ms |
Set a time limit | Stops waiting before the specified time, even if content is still loading |
When to use each
Section titled “When to use each”- Use
ms_delaywhen you need to wait for JavaScript to execute or animations to complete - Use
max_wait_mswhen pages load too much content and you want to capture sooner
Example usage
Section titled “Example usage”Speed up slow pages
Section titled “Speed up slow pages”If a page loads unnecessary content that slows down your screenshot:
{ "url": "https://heavy-website.com", "max_wait_ms": 2000}Combined with ms_delay
Section titled “Combined with ms_delay”You can use both parameters together. The API will wait for ms_delay but not exceed max_wait_ms:
{ "url": "https://example.com", "ms_delay": 1000, "max_wait_ms": 3000}Fast screenshots
Section titled “Fast screenshots”For simple pages where you want quick renders:
{ "html": "<div>Simple content</div>", "max_wait_ms": 500}Common use cases
Section titled “Common use cases”News websites
Section titled “News websites”Many news sites load ads and tracking scripts that delay screenshots:
{ "url": "https://news-site.com/article", "max_wait_ms": 3000, "block_consent_banners": true}E-commerce pages
Section titled “E-commerce pages”Product pages often have heavy JavaScript. Limit wait time to get faster screenshots:
{ "url": "https://shop.example.com/product/123", "max_wait_ms": 4000, "selector": ".product-image"}Batch processing
Section titled “Batch processing”When generating many screenshots, use max_wait_ms to prevent slow pages from blocking your queue:
{ "url": "https://example.com", "max_wait_ms": 5000}Best practices
Section titled “Best practices”- Start with the default - Only use
max_wait_msif screenshots are taking too long - Test your value - Too short a time may result in incomplete screenshots
- Combine with selector - Use
selectorto capture specific elements that load quickly - Consider render_when_ready - For precise control, use
render_when_readyinstead
Need help?
Talk to a human. Email support@htmlcsstoimage.com and we’ll help you get started.