2

There are some old solutions to resolve this question, the one is in github, the other is in stackoverflow.

puppeteer has _client property in lower version. The solution in lower vision as follows:

page._client.send('Network.setBypassServiceWorker', {bypass: true})

The puppeteer version is 18.0.5, so the Page has not _client property.

So the same solution in higher vison as follows:

const client = await page.target().createCDPSession();
await client.send("Network.setBypassServiceWorker", { bypass: true });

But it not working. So how to resolve this problem?

luneice
  • 157
  • 1
  • 10

1 Answers1

0

We should add a new line await client.send("Network.enable") to enable the network. The code as follows:

...
const client = await page.target().createCDPSession();
await client.send("Network.enable");  // Must enable network.
await client.send("Network.setBypassServiceWorker", { bypass: true });
await page.setRequestInterception(true);
...

So we can handle the response in page.on().

...
page.on("response", async (res) => {
    // do somethings.
})
...
luneice
  • 157
  • 1
  • 10