Handle JavaScript-heavy sites, lazy-loaded content, and dynamic elements by waiting before capture.
Many modern websites load content dynamically with JavaScript. Screenshotly provides two mechanisms to ensure content is fully rendered before capturing.
This is more reliable than a fixed delay because it captures as soon as the element exists, rather than waiting an arbitrary amount of time.Use waitForSelector when:
A specific element indicates the page is ready (e.g., a data table, chart, or content container)
Content loads asynchronously and you need to wait for it
Single-page applications (SPAs) render content after JavaScript hydration
You can use delay and waitForSelector together. The API waits for the selector first, then applies the additional delay:
Copy
const screenshot = await client.capture({ url: 'https://example.com/charts', waitForSelector: '.chart-container', delay: 1000 // extra second after element appears});
When capturing SPAs built with React, Vue, or Angular, use waitForSelector targeting a container that only renders after data loads. This is more reliable than guessing a delay value.
If the page takes too long to load or the selector never appears, the request will time out. The default timeout is 30 seconds. You can customize it with the timeout parameter:
If the waitForSelector element never appears on the page, the request will fail after the timeout period. Make sure the selector matches an element that will exist on the target page.