我正在使用 Puppeteer 和 chrome 开发工具来拦截网络响应并在必要时对其进行修改。我使用以下代码。
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 });
});
但这会间歇性地失败(比如 50% 的时间),并出现以下错误
Error: Protocol error (Fetch.continueRequest): Invalid InterceptionId.
什么可能导致这个问题?