I am using Puppeteer and chrome dev tools to intercept network responses and modify them if necessary. I use the following code.
const client = page._client;
await client.send("Fetch.enable", {
patterns: [{ requestStage: "Response" }]
});
client.on("Fetch.requestPaused", async event => {
const { requestId, request, responseStatusCode, responseErrorReason } = event;
console.log(`Request "${requestId}" ${responseStatusCode} ${responseErrorReason} ${request.url} paused.`);
const responseCdp = await client.send("Fetch.getResponseBody", { requestId });
// TODO Modify response
await client.send("Fetch.continueRequest", { requestId });
});
But this fails intermittently (like 50 % of the time) with the following error
Error: Protocol error (Fetch.continueRequest): Invalid InterceptionId.
What could possibly cause this issue ?