电子访问 request/response body 和 headers 来自 window

Electron access request/response body and headers from window

我有一个应用程序可以在单独的 electron 中打开各种网站 windows。我需要在主线程中解析站点发出的任何 AJAX 请求。基本上访问将在开发工具的 chrome 网络选项卡中显示的信息。

我想我可以使用 window.webContents here 但似乎无法在文档中找到正确的函数。

您可以使用 WebRequest 来做到这一点

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