User Agents

Web browsers and everyday web tech, explained

Fix Puppeteer Cluster Browser Page Errors

· 5 min read · Browsers

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through fixing the common “Unable to get browser page” errors that occur when using puppeteer-cluster. These errors usually stem from resource limits, incorrect launch options, or mismatched Puppeteer versions. By the end, you’ll have a stable cluster configuration that handles concurrent tasks without crashing.

What You'll Need

  • Node.js (v14 or later) installed
  • A project with puppeteer and puppeteer-cluster installed (via npm)
  • Basic understanding of async/await in JavaScript

Step-by-Step

  1. Update your dependencies. Run npm install puppeteer@latest puppeteer-cluster@latest in your project root. Version mismatches are a leading cause of browser page errors.
  2. Check your Puppeteer launch options. In your cluster configuration, ensure headless: true (or false if you need a visible browser), and set args to include --no-sandbox and --disable-setuid-sandbox if running as root or in a container.
  3. Increase timeouts. Set timeout in the cluster options to at least 30000 (30 seconds) and retryLimit to 2 or 3. This gives the browser time to spawn and recover from transient failures.
  4. Limit concurrency. Set maxConcurrency to a number your system can handle (e.g., 2 on a small VPS, 5 on a desktop). Too many concurrent browsers exhaust memory and cause page creation failures.
  5. Handle page creation errors explicitly. Wrap your task function in a try-catch and log the error. If you get “Unable to get browser page,” the cluster will retry automatically if retryLimit is set.
  6. Use puppeteer.launch for debugging. Temporarily replace the cluster with a single browser launch to see if the error occurs outside the cluster. If it does, the issue is with Puppeteer itself (e.g., missing system libraries).
  7. Check for zombie processes. After a crash, kill any lingering Chrome processes with pkill -f chrome or pkill -f chromium on Linux/macOS. Then restart your Node script.
  8. Ensure your task function returns a promise. puppeteer-cluster expects an async function. If you use callbacks, the cluster may not wait for the page to close, leading to errors.
  9. Close pages properly. Inside your task, always call page.close() after you're done, or use the page object within a try-finally block to guarantee cleanup.
  10. Test with a minimal script. Create a simple script that just opens a page and prints the title. If that works, gradually add your real logic to isolate the failing part.

Common Mistakes

  • Ignoring resource limits: Running too many concurrent pages on a low-memory machine is the #1 cause. Always monitor memory usage.
  • Not setting --no-sandbox in containers: If you're in Docker or running as root, Puppeteer will fail to launch without this flag.
  • Using an outdated Puppeteer with a newer cluster: The cluster API changes occasionally; always keep both in sync.
  • Forgetting to await the cluster's idle() or close(): This can cause the process to exit before tasks finish, triggering errors.
  • Assuming the error is always a crash: Sometimes it's just a timeout. Increase timeouts before rewriting your whole logic.

Tips

  • Use cluster.on('taskerror') to log errors without crashing. This event gives you the error and the data that caused it.
  • Set monitor: true in cluster options to see live stats. It prints queues, concurrency, and active tasks to the console.
  • Consider using puppeteer-extra with stealth plugin if you're scraping protected sites. But note that it may increase resource usage.
  • Use a dedicated Chromium binary if system Chrome is unstable. You can set the executablePath in launch options.
  • Implement exponential backoff in your task retries. If a page fails to load, wait a few seconds before retrying to avoid hammering the server.

Troubleshooting

If the error persists after following the steps:

  • Check the full stack trace. Run your script with DEBUG=puppeteer-cluster:* node your-script.js to see detailed logs. Look for lines mentioning “Protocol error” or “Target closed.”
  • Verify your system dependencies. On Linux, run ldd $(which chromium) or check Puppeteer's troubleshooting docs for missing libraries like libnss3 or libatk.
  • Test with a different website. Some sites (like Cloudflare-protected ones) may cause the page to hang or close unexpectedly. Try a simple site like example.com.
  • If you're using a proxy, disable it temporarily. Proxy misconfigurations can cause page creation failures.
  • If the error happens intermittently, it might be a memory leak. Monitor memory usage over time and consider restarting the cluster periodically.

Frequently Asked Questions

Why do I get “Unable to get browser page” even with low concurrency?

This often happens when the browser crashes due to missing system dependencies or when the site you're visiting blocks headless browsers. Check your launch args and try adding --disable-gpu.

How do I increase the number of pages per browser?

By default, each worker gets its own browser. To share a browser, you can set workerInstance to false in the cluster options, but this is not recommended for stability.

Can I use puppeteer-cluster with Firefox?

Yes, but you need to set puppeteer.launch({product: 'firefox'}) in the launch options. However, Firefox support is less stable, so stick to Chromium if possible.

What does “taskerror” mean and how do I handle it?

It's an event emitted when a task throws an error. You can listen to it with cluster.on('taskerror', (err, data) => {}) to log or retry manually.

Is it better to use puppeteer-cluster or manage my own pool?

For most use cases, the cluster is easier and handles retries and concurrency well. Managing your own pool is only beneficial if you need very fine-grained control over browser reuse.

Why does my script work locally but fail on a server?

Servers often run as root or in containers, requiring --no-sandbox. Also, servers may have limited RAM or missing fonts. Install fonts and increase memory limits.