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

625
Vistas
How to replay a Puppeteer HTTPRequest?

Using Puppeteer, I am able to intercept HTTPResponses and their HTTPRequests:

page.on("response", async response => {
    let request = response.request(); // Getting the response request
    let responseHeaders = response.headers(); // Check response headers
    response.buffer().then(buffer => {
         // Play with response content
     });
})

Depending on the response content, I need to send the request again like a fresh one and get its response buffer. Instantiating an identical and new request is a valid option.

I know I could use node-fetch as a last resort, but Puppeteer seems to have everything embedded to do it without adding packages.

Do you know how to achieve this?

  • Puppeteer HTTPRequest doc
  • Puppeteer HTTPRequest class
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use page.evaluate to send a post request using fetch API

await page.evaluate(() => {
    return fetch('url', {method: 'POST', body: 'test' }).then(res => res.json())
})

So then you can make a request after the requestfinished event fired.

page.setRequestInterception(true)
page.on('requestfinished', async (request: Request) => {
    let response = request.response()                   // Getting the response request
    let responseHeaders = response.headers()            // Check response headers
    let responseBuffer = await response.buffer()        // Get the buffer required
    let responseJSON = await response.json()            // Get parsed JSON body
    await page.evaluate(([headers, buffer, json]) => {  // Replay request with buffer received
        let someData1 = buffer.toString()               // Change buffer to string type
        let someData2 = headers['Content-Type']         // or maybe use some headers data
        let someData3 = json.properties.value           // or use response data object properties
                                                        // This fetch API below will do the rest
        return fetch('url', { method: 'POST', body: 'test' }).then(res => res.json())
    }, [responseHeaders, responseBuffer, responseJSON])
})
over 4 years ago · Santiago Trujillo 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