nondanee / puppeteer-electron

Use Puppeteer's API with Electron
https://www.npmjs.com/package/puppeteer-electron
MIT License
23 stars 9 forks source link

Response mocking problems #3

Open blohamen opened 4 years ago

blohamen commented 4 years ago

Hi, can somebody help with intercepting requests and response mocking by using this library?

await chartPage.on('request', (req) => {
    if (req.url().includes('TracsProxy')) {
      console.log(req);
      req.respond({
        status: 200,
        contentType: 'text/plain',
        body: JSON.stringify(tracsProxyMock),
      });
    } else {
      req.continue();
    }
  });

I can intersept request but when I setting down mock response I have problem that request doesn't ends up

nondanee commented 4 years ago

You should enable interception by await page.setRequestInterception(true)

But it will raise error

UnhandledPromiseRejectionWarning: Error: Protocol error (Fetch.enable): Fetch domain is only supported with --enable-features=NetworkService

I tried setting that flag in args but cannot launch electron

await puppeteer.launch({headless: false, args: ['--enable-features=NetworkService']})

I also tried npx and can't launch electron as the same

npx electron --enable-features=NetworkService

The electron docs says https://www.electronjs.org/docs/all#breaking-changes-networkservice-draft

We don't currently have an estimate of when we will enable NetworkService by default in Electron, but as Chromium is already removing non-NetworkService code, we might switch before Electron 10.

I'm sorry setRequestInterception is not supported now.