Monitor Puppeteer Performance with Chrome DevTools
In this article
This guide shows you how to monitor Puppeteer scripts using Chrome DevTools and the built-in Node.js inspector. You'll be able to see real-time CPU, memory, network activity, and step through your automation code, making it much easier to find bottlenecks and debug flaky selectors.
What You'll Need
- Node.js installed (v12 or later)
- Puppeteer installed in your project (
npm install puppeteer) - Chrome or Chromium browser (Puppeteer downloads its own by default)
- A basic Puppeteer script you want to profile
Step-by-Step
- Create a test script. Write a simple Puppeteer script, for example
test.js, that navigates to a page and performs some actions. Keep it minimal for now. - Launch Puppeteer with the inspector enabled. In your script, when calling
puppeteer.launch(), add the argument--remote-debugging-port=9222to theargsarray. This opens a debugging port on the browser instance. - Run your script with the Node.js inspector. Instead of running
node test.js, runnode --inspect test.js. This starts the Node.js inspector on port 9229 by default. - Open Chrome DevTools. In a regular Chrome browser (not the one Puppeteer launched), go to
chrome://inspect. You should see your Node.js process listed under “Remote Target”. Click “inspect” to open DevTools attached to your script. - Connect to the Puppeteer browser. In the same DevTools window, click the “Sources” tab, then look for the “Network” or “Console” tab. To see the browser's own performance, open a new tab and go to
http://localhost:9222– you'll see a list of pages Puppeteer has opened. Click on the page you want to debug, then open DevTools for that page by clicking the “inspect” link next to it. - Use the Performance panel. In the DevTools attached to the Puppeteer-controlled page, go to the “Performance” tab. Click the record button, then run your Puppeteer script (or manually trigger actions). When done, stop recording to see a flame chart of CPU activity, network requests, and rendering.
- Monitor memory. In the same DevTools, go to the “Memory” tab. Take a heap snapshot before and after your script runs to compare memory usage. Look for leaks by checking if memory grows steadily over repeated runs.
- Use the Node.js profiler. In the DevTools attached to your Node.js process, go to the “Profiler” tab. Click “Start” to record CPU profiling, then run your script. Stop and analyze the call tree to see which functions in your Puppeteer code take the most time.
- Set breakpoints. In the DevTools attached to Node.js, open your
test.jsfile under the “Sources” tab. Click on a line number to set a breakpoint. When you run the script, it will pause there, letting you inspect variables and step through code. - Watch network activity. In the DevTools attached to the Puppeteer page, go to the “Network” tab. Reload the page or perform actions to see all requests, their timings, and sizes. This helps identify slow resources.
Common Mistakes
- Forgetting to add the remote debugging port. If you don't add
--remote-debugging-port=9222to Puppeteer's launch args, you won't be able to connect to the browser's DevTools. - Using the wrong inspector. Running
node --inspect-brkinstead ofnode --inspectwill pause your script at the very beginning, which can be confusing if you don't expect it. - Confusing the two DevTools windows. You'll have one DevTools for your Node.js script and another for the Puppeteer-controlled page. They are separate; don't mix them up.
- Not closing the browser. When you're done, make sure to close the Puppeteer browser (usually
browser.close()in your script) to free resources.
Tips
- Use
--inspect=0.0.0.0:9229if you need to access the inspector from another machine, but be careful with security. - Set
headless: falsein Puppeteer's launch options to see the browser window and interact with it manually while debugging. - Use
page.waitForTimeout()to simulate slow network conditions if you want to see how your script handles delays. - Save performance profiles and heap snapshots to compare across runs.
- Use the “Coverage” tab in DevTools to see which parts of your CSS/JS are actually used by the page.
Troubleshooting
- Can't see the Node.js process in chrome://inspect. Make sure you ran
node --inspectand that the port 9229 is not blocked. Also check that you're using the same Chrome browser to open chrome://inspect. - DevTools doesn't show the Puppeteer page. Ensure you added
--remote-debugging-port=9222to Puppeteer's args. Also, if you're using a headless browser, you may need to setheadless: falseto see the page in DevTools. - The Performance panel shows nothing. Make sure you started recording before running your script and stopped after. Also, the page must be active in the tab.
- Breakpoints don't hit. Check that you're editing the correct file and that the script is running with the inspector attached. If you use
--inspect-brk, you need to manually resume execution. - Memory heap snapshots are huge. That's normal; they include all objects. Use the comparison view to spot differences.
Frequently Asked Questions
Can I use this with headless Chrome?
Yes, but you won't see the browser window. You can still connect to the page via DevTools using the remote debugging port. To interact visually, set headless: false temporarily.
Do I need to install anything extra?
No, the inspector is built into Node.js and Chrome DevTools is part of Chrome. You only need Puppeteer installed in your project.
Can I profile multiple pages at once?
Yes, each page opened by Puppeteer will appear in the list at http://localhost:9222. You can open DevTools for each page separately.
How do I see the performance of my Puppeteer code vs. the page's code?
The Node.js profiler shows your Puppeteer script's CPU usage. The Performance panel on the page shows the browser's rendering and network. Use both to get the full picture.
Is the remote debugging port secure?
No, it allows any local process to connect. Only use it on your own machine or in a trusted environment. Don't expose it to the internet.
Can I use this with Puppeteer in a Docker container?
Yes, but you need to forward the ports (e.g., -p 9222:9222 and -p 9229:9229) and use --inspect=0.0.0.0 to access from outside.