Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

463
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda