Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Puppeteer times out after 30000 ms on goto, setContent or pdf

ErrorTimeoutError: Timed out after waiting 30000ms

Short answer

Thirty seconds is Puppeteer's default timeout for navigation and for page.pdf. The page did not reach the state you waited for in time. Usually networkidle0 never arrives because a connection stays open, a font or file never loads, or the browser itself is slow in a container. Change what you wait for first, then the time.

  • Applies to Puppeteer 24, Node.js 22 and 24, Express 5, Docker
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find which call waits and with what option. The call with waitUntil: 'networkidle0' or 'networkidle2' is the first suspect.

    grep -rn "waitUntil\|page.pdf\|setDefaultTimeout\|setDefaultNavigationTimeout" --include=*.js . --exclude-dir=node_modules
  2. 2Match what you see, then jump to its fix

    1. 1The timeout happens only with waitUntil: 'networkidle0' or 'networkidle2'; the page is visible in a screenshot long beforenetworkidle0 never happens because a connection stays openFix
    2. 2page.goto succeeds, then page.pdf takes 30 seconds and fails. The HTML links a web font from a host the server cannot reachpage.pdf waits for fonts that never loadFix
    3. 3The page needs more than 30 s even with a good wait condition (large report, slow API behind it)The page is simply slow, and 30 seconds is too shortFix
    4. 4Even a tiny page times out; the app runs in Docker on Alpine, or on Google Cloud Run after the response is sentThe browser is slow because of the container or the hostFix

What does the error look like?

  • TimeoutError: Timed out after waiting 30000ms
  • page.goto, page.setContent or page.pdf rejects after exactly 30 seconds

Cause 1 of 4

networkidle0 never happens because a connection stays open

1Check

The Puppeteer docs define networkidle0 as no more than 0 network connections for at least 500 ms (networkidle2: no more than 2). A page with polling, a websocket, analytics beacons or a streaming request never reaches that state.

const page = await browser.newPage();
page.on('request', (r) => console.log('req', r.url()));
page.on('requestfinished', (r) => console.log('done', r.url()));

2Fix

Wait for the first useful state, then wait for the element you need.

await page.goto(url, { waitUntil: 'domcontentloaded' });
await page.waitForSelector('#report-ready');

3Verify

The route answers well under 30 seconds.

time curl -s -o /dev/null http://localhost:3000/report.pdf

Confirmed by pptr.dev

Did this fix it?

Cause 2 of 4

page.pdf waits for fonts that never load

1Check

The PDF options document waitForFonts, default true: the call waits for document.fonts.ready. A font URL that hangs keeps it pending until the timeout.

grep -n "font-face\|fonts.googleapis\|@import" views/*.ejs public/css/*.css

2Fix

Serve the fonts from your own server, or switch the wait off for this render if the fallback font is fine.

const pdf = await page.pdf({ format: 'A4', printBackground: true, waitForFonts: false });

3Verify

Download the PDF and open it.

curl -o out.pdf http://localhost:3000/report.pdf && file out.pdf

Confirmed by pptr.dev

Did this fix it?

Cause 3 of 4

The page is simply slow, and 30 seconds is too short

1Check

The WaitForOptions page documents timeout with a default of 30000, which Page.setDefaultTimeout or setDefaultNavigationTimeout can change. 0 disables it.

time curl -s -o /dev/null https://example.com/slow-report

2Fix

Set an explicit, larger limit for the slow step instead of removing it, so a hang still ends.

await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 90000 });
const pdf = await page.pdf({ format: 'A4', timeout: 90000 });

3Verify

Run the route with the slow input.

time curl -s -o out.pdf http://localhost:3000/report.pdf

Confirmed by pptr.dev

Did this fix it?

Cause 4 of 4

The browser is slow because of the container or the host

1Check

The Puppeteer troubleshooting page says the Chromium in Alpine 3.20 causes timeout issues, and that Cloud Run turns the CPU off after an HTTP response is written, so a browser launched then is very slow.

grep -n "^FROM" Dockerfile
cat /etc/os-release | head -n 2

2Fix

On Alpine, use the image the page recommends (Alpine 3.19) or a Debian-based image. On Cloud Run, launch and finish the browser work before you send the response, or enable CPU allocation for background work.

# Dockerfile
FROM node:22-alpine3.19

3Verify

Rebuild and request a tiny page.

docker build -t pdf-api . && docker run --rm -p 3000:3000 pdf-api

Confirmed by pptr.dev

Did this fix it?

How do I stop it coming back?

  • Launch one browser at startup and open a new page per request, closing the page in a finally block.
  • Prefer waitForSelector on an element that means 'ready' over any networkidle wait.
  • Keep fonts and images for PDF templates on your own server.
  • Set explicit timeouts on slow steps and log the time each step takes.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.