Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

page.waitForTimeout is gone from Puppeteer

Errorpage.waitForTimeout is not a function

Short answer

Puppeteer removed page.waitForTimeout in version 22, after deprecating it. For a plain pause use a Promise around setTimeout or the timers/promises module in Node.js. Better still, wait for the element or condition you need with waitForSelector or the locator API.

  • Applies to Puppeteer 22, Puppeteer 24, Node.js 22, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find every call so you can decide, one by one, whether it needs a pause or a real wait.

    grep -rn "waitForTimeout" src
  2. 2Match what you see, then jump to its fix

    1. 1Code does await page.waitForTimeout(1000) to pauseA fixed delay was written with the removed methodFix
    2. 2The pause is added after a click or a navigation so the data can loadThe delay hides what the script is really waiting forFix

What does the error look like?

  • page.waitForTimeout is not a function
  • 'waitForTimeout' is deprecated.

Cause 1 of 2

A fixed delay was written with the removed method

1Check

The removal commit deleted the method from Page and Frame. It had been marked deprecated before, and the deprecation text gave the replacement.

npm ls puppeteer

2Fix

Replace the call with a promise around setTimeout. The original ran on the Node.js side, so a Node.js timer is the closest match; the timers/promises module offers the same.

await new Promise((r) => setTimeout(r, 1000));

// or
import { setTimeout as sleep } from "node:timers/promises";
await sleep(1000);

3Verify

Run the script. The pause should last as long as before.

node scrape.js

Confirmed by github.com

Did this fix it?

Cause 2 of 2

The delay hides what the script is really waiting for

1Check

The maintainers discourage waiting for an arbitrary time and point to waiting for the element.

grep -rn "waitForSelector" src

2Fix

Wait for the element that proves the page is ready, or use the locator API, which waits for the element itself.

await page.waitForSelector("#results");

await page.locator("button.load-more").click();

3Verify

Run the script on a slow connection and check that it still finds the data.

node scrape.js

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Wait for selectors and locators, not for fixed times, so the script runs as fast as the page allows.
  • Pin the Puppeteer version in package.json and read the release notes before you bump a major version.
  • Run the type check in CI; a removed method then fails the build.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Back end

cdk synth says --app is required

--app is required either in command-line, in cdk.json or in ~/.cdk.json

The CDK CLI needs a command that runs your app and finds it in three places: the --app option, cdk.json in the project folder, or cdk.json in your home folder.

3 causes, each with a fix

Back end

Mocha or Node cannot find ts-node/register

Error: Cannot find module 'ts-node/register'

Node resolves ts-node/register from your project's node_modules, so the package must be installed there, next to typescript.

2 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.