Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
having puppeteer browser as global instance open at all time vs using new browser instance for each request

i have some web addresses in my db , i need to check these addresses for something and updated them in the db accordingly ... i need to do this over and over

here is simplified version of my code , i have two functions

1 - init -> reads an address row from db , pass the address to second function to check and update the result in db for that address

2 - check_address -> checking that address in the browser and returning the result

here is simplified version of my code

async function init()
{
    try
    {
        let address = 'select * from addressess order by updated_at asc limit 1';
        let result = await check_address(address);
        await address.update({result : result });

    }
    catch(e){}

    setTimeout( ()=> init() , 5000 );
}


async function check_address( address )
{
    var browser = await puppeteer.launch();
    let result = await 'open a tab  , go to the address and cehck';
    // close the browser
    return result ;
}

init(); 

i feel like opening and closing browser for each address is very time/resource consuming , so i thought maybe i could have a global browser open at all time and just open and close tabs in the browser or maybe even use the same tab ... something like

let globalBrowser = false ;
async function check_address( address )
{
    if(!globalBrowser)
    {
        globalBrowser = await puppeteer.launch();
        globalBrowser._process.once('close', () => {
            globalBrowser = false;
        });
    }

    let result = await 'open a tab  , go to the address and cehck';
    return result ;
}

but im not sure if having a browser open at all time is ok , or this flow generally is a good idea

i have very limited experience with puppeteer , i would love some input from someone with more experience and knowledge of long running puppeteer app

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Indeed, opening and closing the browser is performanced heavy. If your script is running on a server you could open the browser initially and do a cron job (@package node-cron) every X hours on the check_adress function.

Instead of closing the browser you could simply close the current page page via:

await page.close();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda