Puppeteer times out after 30000 ms on goto, setContent or pdf
TimeoutError: Timed out after waiting 30000msShort 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.
Fix it fast
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_modules2Match what you see, then jump to its fix
- 1
The 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
page.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
The 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
Even 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
- 1
What does the error look like?
TimeoutError: Timed out after waiting 30000mspage.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.pdfConfirmed by pptr.dev
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/*.css2Fix
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.pdfConfirmed by pptr.dev
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-report2Fix
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.pdfConfirmed by pptr.dev
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 22Fix
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.193Verify
Rebuild and request a tiny page.
docker build -t pdf-api . && docker run --rm -p 3000:3000 pdf-apiConfirmed by pptr.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
Related fixes
Back end
Puppeteer cannot start Chrome on a Linux server
error while loading shared libraries: libnss3.so: cannot open shared object file
Puppeteer prints the real reason below the first line, so read that.
4 causes, each with a fixBack end
Kong Gateway returns 502 'An invalid response was received from the upstream server'
upstream sent too big header while reading response header from upstream
Kong returns 502 when it cannot get a valid HTTP response from the upstream.
4 causes, each with a fixBack end
npm install fails with getaddrinfo ENOTFOUND registry.npmjs.org
npm error errno ENOTFOUND
ENOTFOUND means a DNS lookup for the host failed, so npm never connected.
3 causes, each with a fixBack end
Puppeteer leaves Chrome running after your Express route finishes
Chrome processes still listed by ps after the request has finished
Chrome stays alive when browser.close() is never reached.
3 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
Axios call from a React app comes back 404
404 (Not Found)
Status code 404 means a server answered, but it has nothing at that path.
3 causes, each with a fix