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

188
Visualizações
How to run window.stop after certain time in puppeteer

I want to web scrap a site but the problem with that site is this, content in the site load in 1s but the loader in the navbar kept loading for 30 to 1min so my puppeteer scrapper kept waiting for the loader in the navbar to stop? Is there any way to run window.stop() after a certain timeout

GITHUB

    const checkBook = async () => {
        await page.goto(`https://wattpad.com/story/${bookid}`, {
            waitUntil: 'domcontentloaded',
        });
        const is404 = await page.$('#story-404-wrapper');
        if (is404) {
            socket.emit('error', {
                message: 'Story not found',
            });
            await browser.close();
            return {
                error: true,
            };
        }
        storyLastUpdated = await page
            .$eval(
                '.table-of-contents__last-updated strong',
                (ele: any) => ele.textContent,
            )
            .then((date: string) => getDate(date));
    };
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You could strip the

 waitUntil: 'domcontentloaded',

in favor of a timeout as documented here https://github.com/puppeteer/puppeteer/blob/v14.1.0/docs/api.md#pagegotourl-options

or set the timeout to zero and instead use one of the page.waitFor... like this

await page.waitForTimeout(30000);
about 4 years ago · Juan Pablo Isaza Relatório

0

Similar approach to Marcel's answer. The following will do the job:

page.goto(url)
await page.waitForTimeout(1000)
await page.evaluate(() => window.stop())
// your scraper script goes here
await browser.close()

Notes:

  • page.goto() is NOT awaited, so you save time compared to waiting until DOMContentLoaded or Load events...
  • ...if the goto was not awaited you need to make sure your script can start the work with the DOM. You can either use page.waitForTimeout() or page.waitForSelector().
  • you have to execute window.stop() within page.evaluate() so you can avoid this kind of error: Error: Navigation failed because browser has disconnected!
about 4 years ago · Juan Pablo Isaza 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