Best practices

  • Use `waitUntil: 'networkidle0'` when you need all network connections to be finished, suitable for pages that perform a lot of background tasks.

  • Opt for `waitUntil: 'networkidle2'` to wait until there are no more than 2 network connections for at least 500 ms, which is a good balance between speed and reliability.

  • When using `page.waitForSelector()`, specify whether the element should be visible (`visible: true`) or just present in the DOM.

  • Utilize `page.waitForTimeout()` sparingly as it introduces fixed delays; instead, prefer waiting for specific conditions or elements to improve test efficiency and reliability.

Scrollable code block. Use arrow keys to scroll.

Common issues

  • Ensure that the selector used in `page.waitForSelector()` is accurate and unique to avoid timeouts due to non-existent elements.

  • Adjust the timeout settings in `page.waitForSelector()` and `page.waitForTimeout()` to suit the expected load times and responsiveness of your target website.

  • Keep Puppeteer updated to benefit from improvements and fixes for waiting functions and overall stability.

  • Test different `waitUntil conditions` to find the optimal setting for each specific scenario, as this can significantly affect the performance and reliability of your Puppeteer scripts.

Scrollable code block. Use arrow keys to scroll.

Try Oyxlabs' Proxies & Scraper API

Residential Proxies

Self-Service

Human-like scraping without IP blocking

From

8

Datacenter Proxies

Self-Service

Fast and reliable proxies for cost-efficient scraping

From

1.2

Web scraper API

Self-Service

Public data delivery from a majority of websites

From

49

Useful resources

Puppeteer Tutorial: Scraping With a Headless Browser
Gabija Fatenaite avatar

Gabija Fatenaite

2025-07-30

Puppeteer vs Selenium: Which to Choose
author avatar

Yelyzaveta Hayrapetyan

2025-05-27

How to Bypass CAPTCHA With Puppeteer visuals
How to Bypass CAPTCHA With Puppeteer
Maryia Stsiopkina avatar

Maryia Stsiopkina

2025-03-24

Get the latest news from data gathering world