Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

450
Views
Firebase puppeteer PDF function times out due to Chrome revision

I have a Firebase function to create a PDF file. Lately, it times out due to a "Chrome revision"? Neither do I understand the error message, nor do I understand what is wrong. The function works, when I deploy it locally under MacOS.

TimeoutError: Timed out after 30000 ms while trying to connect to the browser! Only Chrome at revision r818858 is guaranteed to work.
    at Timeout.onTimeout (/workspace/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:204:20)
    at listOnTimeout (internal/timers.js:549:17)
    at processTimers (internal/timers.js:492:7) 

The function:

const puppeteer = require('puppeteer');
const createPDF = async (html, outputPath) => {

    let pdf;

    try {
        const browser = await puppeteer.launch({
            args: ['--no-sandbox']
        });
        const page = await browser.newPage();

        await page.emulateMediaType('screen');

        await page.setContent(html, {
            waitUntil: 'networkidle0'
        });

        pdf = await page.pdf({
           // path: outputPath,
            format: 'A4',
            printBackground: true,
            margin: {
                top: "50px",
                bottom: "50px"
            }
        });

        await browser.close();

    } catch (e) {
        console.error(e);
    }

    return pdf;
};
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

TimeoutError: Timed out after 30000 ms while trying to connect to the browser!

The aforementioned error is coming from the fact that as mentioned in the documentation:

When you install Puppeteer, it downloads a recent version of Chromium

Everytime you're executing Puppeteer you're running a Chromium in the backend to which Puppeteer will try to connect, hence when it can't connect to the browser this errors raises.

After doing multiple test I was able to execute the Cloud Function by adding the parameter headless on the launch option, since the documentation mentions that it should be true by default I don't quite understand why setting it manually allows the Cloud Function to finish correctly. At the beginning I was trying with the timeout set to 0 to disable the error due to timeout, however it seems that it's not required, since by only adding headless it finished correctly, but if you find the same problem with the timeouts you can add it. At the end my code looks like this:

const createPDF = async (html, outputPath) => {

    let pdf;

    try {
        const browser = await puppeteer.launch({
            args: ['--no-sandbox'],
            headless: true,
            timeout: 0
        });
        const page = await browser.newPage();

        await page.emulateMediaType('screen');

        await page.setContent(html, {
            waitUntil: 'networkidle0'
        });

        pdf = await page.pdf({
           // path: outputPath,
            format: 'A4',
            printBackground: true,
            margin: {
                top: "50px",
                bottom: "50px"
            }
        });

        await browser.close();
        console.log("Download finished"); //Added this to debug that it finishes correctly

    } catch (e) {
        console.error(e);
    }

    return pdf;
};
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!