How to Fix Puppeteer Memory Leaks in Production Before They Crash Your Container
Puppeteer memory leaks in production are rarely a single bug — they typically stem from unclosed pages, long-lived browser instances, and orphaned Chromium processes left behind after crashes or timeouts. Developers often misdiagnose the issue by monitoring Node.js heap usage, while the actual memory growth occurs in Chromium's child processes outside the Node process. Key fixes include always closing pages and browser contexts in a finally block, recycling the browser after a set number of jobs rather than keeping one instance alive indefinitely, and running Chromium under an init process to reap zombie processes. Concurrency should be capped and memory ceilings set to limit the damage a single misbehaving page can cause. For use cases limited to capturing screenshots of URLs, a hosted screenshot API can eliminate the need to manage Chromium entirely, removing the memory problem at its source.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in