PDFPipe

Blog

How to run Puppeteer in production

Puppeteer on your laptop is delightful. Puppeteer serving real traffic is a small operations project. If you are going to run it yourself, here is the checklist that keeps it standing.

Recycle browsers, never trust a long-lived one

Chromium memory grows over time. Restart each browser after a fixed number of renders or a memory threshold, and never reuse a single instance for the life of the process. Always close pages and browsers in a finally block so a thrown error does not orphan them.

Bound concurrency

Each browser is heavy. Put a hard limiter in front of rendering and queue beyond it. Unbounded concurrency is the most common cause of timeouts and tab crashes under load.

Container and sandbox flags

  • Install the system libraries Chromium needs, or use a maintained base image.
  • Configure the sandbox correctly rather than blindly disabling it.
  • Set a large enough shared memory size, or pass the flag that avoids it, to prevent crashes.
  • Pin Chromium and Puppeteer versions so a silent update does not break rendering.

Expect these failure modes

OOM kills

Workers creep up in memory and get killed. Recycling and concurrency limits are the fix.

Zombie processes

A render that throws before cleanup leaves a browser holding memory. Clean up in finally.

Cold starts

Launching Chromium on the request path adds seconds. Keep a warm pool or offload.

Or do not run it at all

Everything above is undifferentiated work. A render API gives you the same Chromium output with recycling, isolation, and scaling handled, billed per document. Run Puppeteer for tests; let an API serve production PDFs.

Frequently asked

How do I stop Puppeteer from leaking memory in production?

Recycle browsers after a set number of renders, cap concurrency, and always close pages and browsers in finally. Or offload rendering to an API that handles recycling for you.

Why does Puppeteer crash in my container?

Usually missing system libraries, too little shared memory, or sandbox misconfiguration. Use a maintained base image, set a larger shm size, and configure the sandbox properly.

500 free documents a month, flat pricing after that, and a live playground you can try without signing up.