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

556
Visualizações
Waiting for download to complete on Puppeteer

I have a script made using node.js and puppeteer which downloads a file from a button (which doesn't redirect to a url), so right now i'm using await await page.waitForTimeout(1000); to wait for the download to complete but it has a few flaws, such as:

Depending on the connection, the download might take more than 1000ms to finish, as well as it might take less, which wouldn't make sense to wait more than what took to finish the download.

My question is, is there a way to wait for a download to complete using Node+Puppeteer? I have tried using waitUntil: 'networkidle0 and networkidle2 but both seem to wait forever.

Code below:

const path = require('path');

const puppeteer = require('puppeteer');

(async () => {

  /* Initialize some variables */
  
  const browser = await puppeteer.launch();

// Instantiates a new page
  const page = await browser.newPage(); 

// Gets current path
  const downloadPath = path.resolve('./'); 

// Specifies wether it allows downloading multiple files or not
  await page._client.send('Page.setDownloadBehavior', 
  {behavior: 'allow', downloadPath: downloadPath}); 

// Goes to My Website
  await page.goto('http://localhost:8080/mywebsite');   

// Exports to CSV 
  await page.waitForSelector("#W0009EXPORTAXLS > a > i", {visible: true});
  await page.tap("#W0009EXPORTAXLS > a > i");

  await page.waitForTimeout(1000);

// Log
  console.log('File exported.');

// Closes the browser
  await browser.close(); 
})();
about 4 years ago · Juan Pablo Isaza
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