Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

132
Visualizações
How to play Puppeteer HTTPRequest?

Using Puppeteer , I can 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 content of the response, I need to send the request again as a new one and get its response buffer. Instantiating a new, identical request is a valid option.

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

Do you know how to achieve this?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

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

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

Then you can make a request after the requestfinished event is 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda