Reputation: 9579
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 ?
Upvotes: 5
Views: 4300
Reputation: 113
I wasted some hours on this. I think another cause can be if you do not continue or fulfill the request quickly enough.
If you're debugging your code or logging a lot, this could cause it too maybe? Also, this protocol seems to get broken a lot, so if you're reading this years later, you could also try updating Chrome.
https://github.com/puppeteer/puppeteer/issues/12961#issuecomment-2292941965
A few other causes:
event.responseErrorReason
is set, it seems you don't need to continue the request.Upvotes: 1
Reputation: 9579
Turned out I had made a set of mistakes
page.goto
in my code, which was messing up the interceptor.Correcting them resolve this issue. What came in handy was to run puppetter with headless: false
and inspecting the network of of chromium.
Upvotes: 2