electron 获取response 拦截所有的返回数据
electron 获取response 拦截所有的返回数据
注意对性能有所影响
main.js中
主线程中加入下面的代买
import {
app,
BrowserWindow,
shell,
ipcMain,
Menu,
session,
Tray,
protocol,
} from "electron";
try {
mainWindow.webContents.debugger.attach('1.3');
} catch (err) {
console.log('Debugger attach failed: ', err);
}
mainWindow.webContents.debugger.on('detach', (event, reason) => {
console.log('Debugger detached due to: ', reason);
});
mainWindow.webContents.debugger.on('message', (event, method, params) => {
if (method === 'Network.responseReceived') {
console.log(params.response.url);
mainWindow.webContents.debugger.sendCommand('Network.getResponseBody', { requestId: params.requestId }).then(function(response) {
console.log(response);
});
}
})
mainWindow.webContents.debugger.sendCommand('Network.enable');
https://www.electronjs.org/docs/latest/api/debugger