简体   繁体   English

错误:协议错误(Fetch.continueRequest):InterceptionId无效

[英]Error: Protocol error (Fetch.continueRequest): Invalid InterceptionId

I am using Puppeteer and chrome dev tools to intercept network responses and modify them if necessary.我正在使用 Puppeteer 和 chrome 开发工具来拦截网络响应并在必要时修改它们。 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但这会间歇性地失败(比如 50% 的时间)并出现以下错误

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

What could possibly cause this issue ?什么可能导致这个问题?

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.我意识到我的代码中有 2 个page.goto实例,这弄乱了拦截器。

Correcting them resolve this issue.更正它们可以解决此问题。 What came in handy was to run puppetter with headless: false and inspecting the network of of chromium.派上用场的是运行 puppetter with headless: false并检查铬的网络。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM