await page.setContent(html) waits for the page’s load lifecycle event by default. To wait only for document parsing, pass { waitUntil: 'domcontentloaded' }. If your page creates important content after either event, wait separately for the element or application state your next step needs.
What page.setContent() waits for
Puppeteer’s Page.setContent(html, options) assigns the supplied markup to the page and returns a promise that resolves when its configured wait condition is met. It does not return the HTML. The default waitUntil value is 'load'. Puppeteer Page.setContent API
As an Amazon Associate I earn from qualifying purchases.
The API’s wait options also allow 'domcontentloaded'. You can pass an array of lifecycle events; the wait succeeds only after all events in that array have fired. SetContentWaitForOptions
Recommended Free Tools
Choose the right readiness condition
Wait for the load event
Use the default when the next operation should wait for the page’s load event:
#1 Best Overall
await page.setContent('<main><h1>Report</h1></main>');
Wait for document parsing
Use domcontentloaded when parsing the document is enough and you do not need to wait for load:
await page.setContent(html, { waitUntil: 'domcontentloaded' });
These are different lifecycle milestones: domcontentloaded signals that the document has been parsed, while load waits for the load event. PuppeteerLifeCycleEvent
Rank #2
- HTML CSS Design and Build Web Sites
- Comes with secure packaging
- It can be a gift option
Wait for application-specific content
A lifecycle event does not establish that an application has finished its own asynchronous work. If the next action depends on a particular element or state, wait for that condition explicitly. Puppeteer recommends locators for interactions; the example below waits for an element matching a selector. Replace it with a condition that reliably indicates readiness in your page.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsawait page.setContent(html, { waitUntil: 'domcontentloaded' });
await page.locator('[data-ready="true"]').wait();
Puppeteer also documents the lower-level waitForSelector method. Page interactions
Rank #3
- Brand: Wiley
- Set of 2 Volumes
- A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
Wait for network quiet only when that is what you need
The current SetContentWaitForOptions type excludes 'networkidle0' and 'networkidle2'. Although Puppeteer defines those lifecycle values generally as network-connection thresholds sustained for at least 500 ms, they are not supported as setContent()’s waitUntil values in that type. SetContentWaitForOptions · PuppeteerLifeCycleEvent
When network quiet is genuinely the condition you require, use the separate page.waitForNetworkIdle() method. Its documented defaults are an idleTime of 500 ms and concurrency of zero; it waits at least the configured idle time. Network quiet is not a substitute for checking that a particular app element or state is ready. Page.waitForNetworkIdle · WaitForNetworkIdleOptions
Rank #4
Timeouts and multiple lifecycle events
setContent() accepts the general wait options because its options extend WaitForOptions. The documented default timeout is 30,000 ms; setting timeout: 0 disables it. You can change the default with page.setDefaultTimeout() or page.setDefaultNavigationTimeout(). WaitForOptions
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →// Require both lifecycle events.
await page.setContent(html, {
waitUntil: ['domcontentloaded', 'load'],
timeout: 30_000,
});
// Disable the timeout only when an unlimited wait is intentional.
await page.setContent(html, { timeout: 0 });
Common problems and fixes
- The call resolves, but the expected app content is missing: the configured lifecycle event may have fired before the app-specific condition was ready. Add a locator or another condition wait for the content required by the next step.
networkidle0ornetworkidle2is rejected as awaitUntilvalue: the currentsetContent()wait type excludes them. Use a supported lifecycle event and, if network quiet is actually needed, callpage.waitForNetworkIdle()separately.setContent()times out: the configured condition did not complete before the timeout. Check that the chosen lifecycle event is appropriate, review any custom timeout settings, and wait for a narrower application condition when that is what the next step requires.- You need to inspect, not replace, the page HTML:
page.content()is a separate read operation. It returns the full HTML contents, including the DOCTYPE; it does not set markup or control whensetContent()resolves. Page.content API
Version note
Puppeteer’s API pages identify version 25.12.0, while the referenced SetContentWaitForOptions page is from the Next documentation and may differ from the current stable API. Check your installed Puppeteer version and its corresponding documentation when relying on version-sensitive types or examples.
Best Value
Or skip the browser setup
If your goal is to capture a website rather than set custom HTML in Puppeteer, ScreenshotNeo provides a screenshot API and MCP server. One GET request can return a screenshot or PDF; cookie banners, popups and chat widgets are removed before capture, and bot checks, blank pages and failed loads are not billed. AI agents can use its MCP server, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.
See the ScreenshotNeo API documentation. Example cURL request:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Sign up for 1,000 free screenshots a month, with no card required.
Frequently Asked Questions
Does page.setContent() wait for the page to load?
Yes. Its default wait condition is the load event; choose another supported condition with waitUntil if needed.
Does page.setContent() return the supplied HTML?
No. It returns a promise that resolves when the configured wait condition is met.
Can I use networkidle0 in setContent()?
The current SetContentWaitForOptions type excludes it. Use page.waitForNetworkIdle() separately if network quiet is the condition you need.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




