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

183
Vistas
How i do a simple loop on a event?

I searched everywhere a simple example for loop a event whiteout the processor up to 70%. I don't find the awsner so i need help. I just need to everytime the page refresh it do the code.

Here the code:

page.once('load', async () => {
console.log("Page loaded!")
// Example of code to execute when the page reload
const searchBtn =  await login.$x("//button[@id='btnEnter']");
await searchBtn[0].click();
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need code which executes everytime the page was loaded. You can achieve that by calling

function onLoadHandler() { 
 /**code goes here ***/ 
}
page.on('load', onLoadHandler)

You do not have to loop over this. Your onLoadHandler function will be executed everytime this particular page is reloaded.

What you did is to call page.once('load', onLoadHandler). This listens to the 'load' event once and then the handler removes it selve, it does it "once".

Loop

So probably if you looped the function page.once()(doing it 10000 times a sec) using a while loop or something your processor would ofc reach 70% usage .. Whenever your processor goes crazy like this, your code is suspected to be way to ressource heavy. In general that should not happen when running normal app without handling 10k requests per second or something.

Feel free to leave a comment.

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