Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
¿Como reproducir Puppeteer HTTPRequest?

Usando Puppeteer , puedo interceptar HTTPResponses y sus 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
     });
})

Dependiendo del contenido de la respuesta, necesito enviar la solicitud nuevamente como una nueva y obtener su búfer de respuesta. Instanciar una solicitud idéntica y nueva es una opción válida.

Sé que podría usar node-fetch como último recurso, pero Puppeteer parece tener todo incorporado para hacerlo sin agregar paquetes.

¿Sabes cómo lograr esto?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar page.evaluatepara enviar una solicitud de publicación usando la API de búsqueda

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

Entonces puede hacer una solicitud después de requestfinishedque se dispare el evento.

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!