
You upgraded Puppeteer and a script that worked for years now throws:
TypeError: page.waitForTimeout is not a function
Nothing is wrong with your code's logic — the method is gone. `page.waitForTimeout()` was deprecated in Puppeteer 21 and **removed in Puppeteer 22** (early 2024). Every tutorial written before then still tells you to use it, which is why this error keeps appearing in new projects.
If you just need the old behavior back, use a plain promise-based sleep:
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
await page.goto("https://example.com");
await sleep(2000);
await page.screenshot({ path: "screenshot.png" });
Node 16+ also ships one in the standard library:
import { setTimeout as sleep } from "node:timers/promises";
await sleep(2000);
Puppeteer removed the method deliberately — fixed sleeps are the leading cause of flaky automation. Two seconds is too long on a fast page and too short on a slow one. Wait for the thing you actually need:
// Wait for an element to exist
await page.waitForSelector(".chart-rendered");
// Wait for an arbitrary condition
await page.waitForFunction(() => window.dataLoaded === true);
// Wait for the network to go quiet
await page.waitForNetworkIdle({ idleTime: 500 });
Each of these resolves the moment the page is ready, instead of guessing.
A very common reason for `waitForTimeout` in old scripts is "give the page time to finish rendering before the screenshot." That is a solved problem in a screenshot API — readiness handling is a parameter, not a guess:
const response = await fetch("https://api.screenshotty.link/api/v1/screenshot", {
method: "POST",
headers: {
"X-Api-Key": process.env.SCREENSHOTTY_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
url: "https://example.com",
ready_event: "networkidle", // wait for the network to settle
wait_ms: 1000, // optional extra settle time
scroll_to_bottom: true, // trigger lazy-loaded content
}),
});
No Puppeteer versions to track, no removed methods, no browser fleet. [Screenshotty](/) has a free tier of 100 screenshots per month — see the [Node.js screenshot guide](/screenshot-api/nodejs) or try the [free screenshot tool](/website-screenshot) first.