0

I have an application that opens various websites in separate electron windows. I need to parse any AJAX request the sites make, in the main thread. Basically access the information that would be shown in the chrome network tab of the dev tools.

I think I can use the window.webContents here but can't seem to find the right function in the documentation.

Rafael
  • 130
  • 10

1 Answers1

0

You can use WebRequest to do this

const { BrowserWindow } = require('electron')

const win = new BrowserWindow({ width: 800, height: 600 })
win.loadURL('YOUR_URL')

const webRequest = win.webContents.session.webRequest

// use webRequest to intercept requests
aabuhijleh
  • 2,214
  • 9
  • 25
  • Any idea how I can get the response body out of that? The listener objects seem to only give the headers and other info. – Rafael Aug 17 '21 at 11:38
  • @Rafael if you want to access the response body, see [this question](https://stackoverflow.com/q/61789895/9698583) and the comments on it. Hope it helps – aabuhijleh Aug 18 '21 at 06:37