October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

Puppeteer setContent(): How to Wait for Page Content to Load

Puppeteer setContent waits for the load event by default. Choose a supported lifecycle threshold or add a separate wait for the app-specific content your next step needs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

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
Sale
HTML and CSS: Design and Build Websites
  • 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.setContent(html, { waitUntil: 'domcontentloaded' });
await page.locator('[data-ready="true"]').wait();

Puppeteer also documents the lower-level waitForSelector method. Page interactions

Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • 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

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

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
// 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.
  • networkidle0 or networkidle2 is rejected as a waitUntil value: the current setContent() wait type excludes them. Use a supported lifecycle event and, if network quiet is actually needed, call page.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 when setContent() resolves. Page.content API
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.