---
title: Fix Puppeteer Performance & Memory | TestingBot
description: Discover practical tips to fix Puppeteer performance issues, speed up
  slow script execution, lower high memory usage, block unnecessary resources and
  improve automation efficiency.
source_url:
  html: https://testingbot.com/software-testing-questions/how-to-handle-puppeteer-performance-issues
  md: https://testingbot.com/software-testing-questions/how-to-handle-puppeteer-performance-issues.md
---

# How to handle Puppeteer performance issues?

- [![Share on Facebook](https://static.addtoany.com/buttons/facebook.svg) ](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname= "Share on Facebook")
- [![Share on Twitter](https://static.addtoany.com/buttons/twitter.svg) ](https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname= "Share on Twitter")
- [![Share on LinkedIn](https://static.addtoany.com/buttons/linkedin.svg) ](https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname= "Share on LinkedIn")
- [![Share on HackerNews](https://static.addtoany.com/buttons/y18.svg) ](https://www.addtoany.com/add_to/hacker_news?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname= "Share on HackerNews")

Puppeteer is a powerful NodeJS library that enables automated control over Chromium-based browsers. While it’s widely used for automation, scraping and testing, you may encounter performance issues like slow script execution, excessive memory consumption or browser crashes when working with complex pages or large-scale tasks. Here are practical tips and best practices to handle these performance issues effectively.

## 1. Optimize page loading and navigation

- **Use `page.goto()` with proper options:** Add `waitUntil: 'networkidle0'` or `'domcontentloaded'` to control when the script proceeds, avoiding unnecessary waits. 

```javascript
await page.goto('https://example.com', { waitUntil: 'networkidle0' });
```

- **Avoid loading unnecessary resources:** Use request interception to block images, fonts, ads, or analytics scripts that are not needed. 

```javascript
await page.setRequestInterception(true); page.on('request', (req) => { if (['image', 'stylesheet', 'font'].includes(req.resourceType())) { req.abort(); } else { req.continue(); } });
```

## 2. Reduce memory consumption

- **Close pages when they’re no longer needed:** Avoid keeping multiple tabs open. 

```javascript
await page.close();
```

- **Use `browserContext` for isolation:** Instead of opening many separate browser instances, use multiple contexts within one instance. 

```javascript
const context = await browser.createIncognitoBrowserContext(); const page = await context.newPage();
```

- **Call `page.evaluate()` carefully:** Minimize passing large objects between Node.js and the browser context, as this can cause memory leaks.

## 3. Optimize script execution

- **Use `page.evaluate()` efficiently:** Execute minimal, focused scripts inside the browser context. 

```javascript
await page.evaluate(() => { document.querySelector('#button').click(); });
```

- **Throttle execution:** Add small delays when scraping large datasets to avoid overwhelming the browser or server. 

```javascript
await new Promise(resolve => setTimeout(resolve, 100));
```

## 4. Monitor and debug performance

- **Enable Chromium DevTools Protocol:** Use `client.send('Performance.enable')` to capture metrics like CPU usage, memory, and network. 

```javascript
const client = await page.target().createCDPSession(); await client.send('Performance.enable'); const metrics = await client.send('Performance.getMetrics');
```

- **Run with `--disable-dev-shm-usage`:** When running Puppeteer in Docker, use this flag to prevent shared memory issues.
- **Use headless mode strategically:** Sometimes running in `headless: false` helps reveal visual issues slowing things down.

## 5. Keep Chromium and Puppeteer updated

New releases often include performance improvements, bug fixes, and better memory management. Regularly update your Puppeteer package and review the release notes.

## Example: Putting it all together

```javascript
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (req) => {
  if (['image', 'stylesheet', 'font'].includes(req.resourceType())) {
    req.abort();
  } else {
    req.continue();
  }
});

await page.goto('https://testingbot.com', { waitUntil: 'networkidle0' });
// Perform actions...
await page.close();
await browser.close();
```

## Cloud-based Puppeteer testing

TestingBot provides remote browsers in the cloud, allowing you to [run multiple Puppeteer tests in parallel](https://testingbot.com/support/web-automate/puppeteer), without having to worry about performance issues or maintenance.

- [![Share on Facebook](https://static.addtoany.com/buttons/facebook.svg) ](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname=)
- [![Share on Twitter](https://static.addtoany.com/buttons/twitter.svg) ](https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname=)
- [![Share on Linkedin](https://static.addtoany.com/buttons/linkedin.svg) ](https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname=)
- [![Share on Hacker News](https://static.addtoany.com/buttons/y18.svg) ](https://www.addtoany.com/add_to/hacker_news?linkurl=https%3A%2F%2Ftestingbot.com%2Fsoftware-testing-questions%2Fhow-to-handle-puppeteer-performance-issues.md&linkname=)

 ![TestingBot Logo](https://testingbot.com/assets/logo-head-2f7f08db4ac9c4a3b1a784047410f8a4ece708e7e9f10ed16e20fdd8310f8de3.svg)

## Sign up for a Free Trial

Start testing your apps with TestingBot.

No credit card required.

[Start Free Trial](https://testingbot.com/users/sign_up)

## Other Questions

### [Find out what exactly a test-suite is, with regards to automted testing](https://testingbot.com/software-testing-questions/what-is-a-test-suite "Find out what exactly a test-suite is, with regards to automted testing")

### [What is Geolocation Testing?](https://testingbot.com/software-testing-questions/what-is-geolocation-testing "What is Geolocation Testing?")

### [Use an online browser sandbox for security and privacy.](https://testingbot.com/software-testing-questions/what-is-an-online-browser-sandbox "Use an online browser sandbox for security and privacy.")

### [Learn about remote browsers and how to use them.](https://testingbot.com/software-testing-questions/what-is-a-remote-browser "Learn about remote browsers and how to use them.")

### [Learn about browser censorship, privacy and tracking.](https://testingbot.com/software-testing-questions/what-is-an-uncensored-browser "Learn about browser censorship, privacy and tracking.")

### [The difference between an Alert and a Popup](https://testingbot.com/software-testing-questions/what-is-the-difference-between-an-alert-and-a-popup "The difference between an Alert and a Popup")
