Muthukumar
Muthukumar

Reputation: 9579

Error: Protocol error (Fetch.continueRequest): Invalid InterceptionId

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

Answers (2)

user2522165
user2522165

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:

  1. Too many requests, try to narrow the filters when setting Fetch.enable.
  2. If event.responseErrorReason is set, it seems you don't need to continue the request.

Upvotes: 1

Muthukumar
Muthukumar

Reputation: 9579

Turned out I had made a set of mistakes

  1. Some of the resources I was loading was not valid, like the file path did not exist and file format was not correct and so on.
  2. I realised I had 2 instances of 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

Related Questions