microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.47k stars 3.64k forks source link

[Question] Is it possible to mock Electron http request/responses in the main process? #14095

Closed matt-potts-autodesk closed 2 years ago

matt-potts-autodesk commented 2 years ago

First of all thank you for adding experimental support for Electron, this is awesome.

I was wondering if it was possible to mock http requests/responses in the main process. I see from the examples this looks to be possible via the page.route api which would only be catching requests in the renderer. The project I am working on we make all of our network requests in the main process then pass the data to the UI via ipcRenderer.

Any advice would be appreciated.

pavelfeldman commented 2 years ago

We only intercept network requests that are going through the browser network stack. If you are using require('http') or alike, you would beed to use some Node mocking library to achieve the same in the main process.