October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Set a Timeout for a Puppeteer Locator

Configure a timeout for one Puppeteer locator with setTimeout(milliseconds), or set a page default inherited by locators that do not override it.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Set a timeout on the locator before calling its action: await page.locator('button').setTimeout(3000).click(); The value is in milliseconds. setTimeout() returns a new locator configured with that timeout; use 0 to disable the locator timeout. Locators otherwise inherit the page’s default timeout.

Set a timeout for one locator

Call .setTimeout(milliseconds) before the locator action. For example, give a submit button up to 10 seconds to become ready and click:

As an Amazon Associate I earn from qualifying purchases.

await page.locator('button.submit').setTimeout(10_000).click();

The timeout applies to the action on that configured locator. The value is measured in milliseconds. Puppeteer documents 3000 as an example; it is not a universal recommendation. Choose a limit that fits the page’s expected behavior, and investigate a timeout rather than simply making every wait longer.

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

Runnable example

With Puppeteer installed in a Node.js project, this example opens a page, configures a locator timeout, and attempts a click. Replace the URL and selector with ones for the page you control.

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com');

    await page.locator('button.submit').setTimeout(10_000).click();
  } finally {
    await browser.close();
  }
})();

The example assumes that the target page has a matching button.submit and that it can be clicked. A locator timeout cannot make a missing element or an incorrect selector succeed.

Choose between a locator timeout and a page default

Use a locator override when one action needs a different limit. Use page.setDefaultTimeout(milliseconds) when locators on that page should share a default. Locators without their own timeout inherit the page setting.

Setting Scope Example
Locator override That configured locator’s action page.locator('button.submit').setTimeout(10_000).click()
Page default Default timeout inherited by locators on the page page.setDefaultTimeout(5000)
Disable locator timeout That configured locator page.locator('button').setTimeout(0).click()
page.setDefaultTimeout(5000);

// This locator has its own 10-second timeout.
await page.locator('button.submit').setTimeout(10_000).click();

// This locator inherits the page's 5-second default.
await page.locator('button.cancel').click();

Locator.setTimeout() returns a new locator instance, so keep and use the returned locator in the action chain. Setting a locator timeout is not the same as configuring navigation timeouts; this setting does not change how long navigation is allowed to take.

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

What a locator timeout waits for

A locator action waits for the element and for the action’s readiness conditions. For a click, those conditions include being in the viewport, visible and enabled, with a stable bounding box. If the element is not found or the required state is not reached before the timeout, Puppeteer throws a TimeoutError. Locator actions retry when readiness checks fail.

Increasing the timeout helps only when the page is expected to reach the required state but needs more time. It does not correct a selector that matches nothing or a readiness assumption that does not fit the page.

Troubleshoot a locator timeout

  • The selector does not match: Check the selector against the page’s actual DOM and confirm the element exists in the context where the locator is used.
  • The element appears but the action still times out: Check the action’s readiness requirements. For a click, confirm the element becomes visible, enabled, in the viewport and stable.
  • Only one control is slow: Set a longer timeout on that locator rather than changing the page default for every locator.
  • Many locators need a different shared limit: Set page.setDefaultTimeout(milliseconds) and use locator-specific overrides only for exceptions.
  • You are considering setTimeout(0): This disables the locator timeout rather than fixing the cause of a wait. Prefer a finite limit unless an unbounded wait is intentional.
  • The wait concerns navigation: A locator timeout configures locator actions, not navigation. Use the separate navigation-timeout API for navigation behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If the goal is to capture a website rather than interact with it in Puppeteer, ScreenshotNeo can return a screenshot from one GET request. For example, save a WebP screenshot of the target URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for request options. Cookie banners, popups and chat widgets are removed before the shot; bot checks, blank pages and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000 shots.

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

Sign up for 1,000 free screenshots a month, with no card required.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition

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.

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.