Why this error happens
If you see an error like:
TypeError: page.waitForTimeout is not a functionyour code is probably running on the old version of Puppeteer.
page.waitForTimeout() was removed, so older examples and blog posts that still use it will fail after an upgrade.
What to use instead
In most cases, the correct replacement is not another sleep function. It is an explicit wait for the thing you actually need.
Use:
page.waitForSelector()when you need an element to appear;page.waitForNavigation()when a click or submit triggers navigation;page.waitForResponse()when you need a specific API call to finish;page.waitForFunction()when you need a client-side condition to become true;page.waitForNetworkIdle()when you want the page to become quiet after navigation.
If you are looking for page.goto(..., { waitUntil: ... }) guidance, read Puppeteer waitUntil: how to wait for page load.
Replacements for common cases
Wait for a selector instead of sleeping
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000 });await page.waitForSelector(".price", { visible: true, timeout: 10_000,});Wait after a click that navigates
const [response] = await Promise.all([ page.waitForNavigation({ waitUntil: ["domcontentloaded", "networkidle2"], timeout: 30_000, }), page.click("a.next-page"),]);Wait for a specific API response
await page.click("button.refresh");
await page.waitForResponse((response) => { return response.url().includes("/api/data") && response.ok();});Wait for a client-side condition
await page.waitForFunction(() => { return document.querySelectorAll(".result-card").length >= 10;});Wait for the network to calm down
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000 });
await page.waitForNetworkIdle({ idleTime: 500, timeout: 10_000,});If you still need a fixed delay
Sometimes a short delay is still the simplest fallback, especially for one-off scripts.
Use a standard JavaScript promise:
await new Promise((resolve) => setTimeout(resolve, 2000));That is the closest drop-in replacement for page.waitForTimeout(2000), but it is usually the weakest solution:
- it can still be too short on slow pages;
- it can waste time on fast pages;
- it does not describe what the code is actually waiting for.
Migration example
Old code:
await page.goto(url);await page.waitForTimeout(5000);await page.screenshot({ path: "page.png" });Better modern version:
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000,});
await page.waitForNetworkIdle({ idleTime: 500, timeout: 10_000,});
await page.screenshot({ path: "page.png" });Best version, when you know the exact ready signal:
await page.goto(url, { waitUntil: "domcontentloaded", timeout: 30_000,});
await page.waitForSelector(".chart-container", { visible: true, timeout: 10_000,});
await page.screenshot({ path: "page.png" });Summary
page.waitForTimeout() is gone in Puppeteer.
You can replace it with:
- an explicit Puppeteer wait method for the event you care about;
new Promise((resolve) => setTimeout(resolve, ms))if you really need a plain delay.
For navigation readiness and waitUntil options, see Puppeteer waitUntil: how to wait for page load.