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

181
Vistas
How to deep copy a page of puppeteer in javascript?

I'm using puppeteer to navigate my website. I want to wait for an api that sometimes gets called and sometimes not. I'm using

await page.waitForResponse((response =>response.url().includes(myurl)), { timeout: 1000 });

to wait for that api. This works fine when the api gets called, but whenever the api doesn't get called, it crashes and the page isn't same anymore. So, I want to deep copy the page so that I can just check for the api via it's copy and even if that page gets damaged. I will have another that I can use.

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

0

I think you don't need to copy your page. That's probably not doable very easy and seems like a bit of overkill. Instead, preventing the page from crashing would be a simpler approach.

Try something like this:

async function waitForApi(url, timeoutMs) {
   try {
       console.log('waiting ', timeoutMs+'ms for special API. url:', url);
       const opts = { timeout: timeoutMs || 1000 };
       await page.waitForResponse(response => response.url().includes(url), opts);
       console.log('Special API was called!.');
       return true;
   } catch(err) {
       console.log('Special Api was appearantly not called. (Or may be failed.. Error:', err);
       return false;
   }
}
 
// example call of waitForApi .. 
const myUrl = '...'
const apiCalled = await waitForApi(myUrl, 1000)

if(apiCalled) {
   // do stuff if you want to..
} else {
   // do stuff if you want to..
}

This should now log if the api was called or not and when needed you can handle the cases differently.

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