Last active
June 6, 2024 20:53
-
-
Save d-kja/a5bbe2ed9b368de2be2a3d5f4bb70d2b to your computer and use it in GitHub Desktop.
intercept-response-body-puppeteer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const client = await page.target().createCDPSession(); | |
await client.send("Fetch.enable", { | |
patterns: [{ requestStage: "Response" }] | |
}); | |
client.on('Fetch.requestPaused', async parameters => { | |
const { requestId } = parameters | |
const responseCdp = await client.send("Fetch.getResponseBody", { requestId }); | |
const responseBody = responseCdp.base64Encoded ? Buffer.from(responseCdp.body, 'base64') : responseCdp.body; | |
console.log({ | |
bodyLength: responseCdp.body.length, | |
body: responseBody.toString() | |
}); | |
await client.send("Fetch.continueRequest", { requestId }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment