What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use Puppeteer’s page.setContent(html, options?) method to replace a page’s document content with an HTML string. Await it before running the next step:
await page.setContent(`<!doctype html>
<html>
<head><title>Example</title></head>
<body><main><h1>Hello</h1></main></body>
</html>`);
setContent returns a promise that resolves to void. It accepts markup, not a URL. See the Puppeteer Page.setContent API reference.
As an Amazon Associate I earn from qualifying purchases.
Set HTML on a page
Call page.setContent(html) with the markup string, then await the promise before querying or interacting with the resulting page. A fragment is sufficient when you only need elements in the current page context; use a full document when you need document-level structure such as a title or explicit head and body.
Recommended Free Tools
await page.setContent('<main><h1>Rendered markup</h1></main>');
const heading = await page.$eval('h1', element => element.textContent);
console.log(heading); // Rendered markup
The method sets supplied HTML as the page content; it does not navigate to a web address. For navigation to a URL, use a navigation method instead.
#1 Best Overall
Choose a wait condition and timeout
The optional second argument follows Puppeteer’s wait-options contract. The documented default lifecycle condition is load, and the documented default timeout is 30,000 milliseconds. You can set them explicitly:
await page.setContent(html, {
waitUntil: 'load',
timeout: 30_000,
});
Use a lifecycle condition that fits the operation rather than increasing the timeout automatically. If waitUntil is an array of lifecycle events, Puppeteer waits for every named event in the array. The available options and defaults are described in the WaitForOptions reference.
Rank #2
You can also set a shared navigation timeout with page.setDefaultNavigationTimeout(milliseconds); Puppeteer documents that it applies to page.setContent as well. A per-call timeout lets you use a different limit for one call. See setDefaultNavigationTimeout.
Wait for the state your next step needs
Completion of setContent is not necessarily the same as an application-specific readiness condition. If later work depends on a particular element or state, wait for that explicitly after setting the markup.
Wait for an element
await page.setContent('<div id="app"></div>');
await page.waitForSelector('#app');
waitForSelector supports visibility and hidden-state conditions, a timeout, and an abort signal; see the waitForSelector reference.
Wait for an application condition
When readiness is represented by a JavaScript condition rather than the presence of an element, use waitForFunction:
Rank #4
await page.waitForFunction(() => window.appReady === true);
It waits until a function evaluated in the browser context returns a truthy value. Node.js arguments can also be passed to the function. See the waitForFunction reference. For interactions with elements, Puppeteer’s locator guide describes locators that wait for an element to be present and in the right state: Page interactions.
Set content inside a frame
Use frame.setContent when the target is a particular iframe or other frame, rather than the main page. Find and validate the frame before setting its markup:
Best Value
- Used Book in Good Condition
const frame = page.frames().find(candidate => candidate.name() === 'preview');
if (!frame) throw new Error('Preview frame not found');
await frame.setContent('<p>Frame content</p>');
Frame.setContent accepts an HTML string and optional wait options, following the same basic pattern. See the Frame.setContent API reference.
Handle untrusted markup carefully
The API assigns the supplied string as page markup; the method reference does not promise to sanitize untrusted HTML or prevent scripts and external resources from running. Treat untrusted markup as browser content and apply the security controls appropriate to your application. Do not rely on setContent itself as a sanitizer.
Troubleshoot common problems
- The following query runs too early: ensure the
setContentcall is awaited. Then addwaitForSelectororwaitForFunctionif the next step relies on a specific element or application state. - The call times out: check which lifecycle condition is being awaited and whether it matches the task. Set a suitable per-call
timeoutor adjust the page’s default navigation timeout; a larger value alone does not establish that the application is ready. - The wrong content changes: confirm whether the target is the main page or an iframe. Use
page.setContentfor the page and the correspondingframe.setContentfor a frame. - A URL appears where markup is expected:
setContentaccepts an HTML string, not a URL. Use a navigation method when the intent is to load a website. - The frame lookup fails: verify that the frame exists and that its name matches before calling
setContent; frame names are only one possible way to identify the target.
Or skip the browser setup
If your goal is a website screenshot rather than running a Puppeteer browser yourself, ScreenshotNeo offers a one-request capture API. Cookie banners, newsletter popups and chat widgets are removed before capture; bot checks, blank pages and failed loads are never billed. An MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. See the ScreenshotNeo website and API documentation.
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.
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.




