首页 > 其他分享 >electron 获取response 拦截所有的返回数据

electron 获取response 拦截所有的返回数据

时间:2022-10-04 23:37:00浏览次数:55  
标签:console debugger response electron log 拦截 mainWindow webContents

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

标签:console,debugger,response,electron,log,拦截,mainWindow,webContents
From: https://www.cnblogs.com/Ferdinand-B/p/16754804.html

相关文章