1

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 ?

Muthukumar
  • 8,679
  • 17
  • 61
  • 86

1 Answers1

1

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.

Muthukumar
  • 8,679
  • 17
  • 61
  • 86