const listenAllRequests = (childWindow) => {
// 启用调试器, 可以选填DevTools 协议版本号,默认省略, Electron 会自动使用与当前 Electron 版本兼容的最新 DevTools 协议版本
childWindow.webContents.debugger.attach();
// 启用网络跟踪
childWindow.webContents.debugger.sendCommand('Network.enable');
// 监听网络响应
childWindow.webContents.debugger.on('message', (event, method, params) => {
// 处理响应, method(事件名称), Network.responseReceived表示网络请求的响应已经收到
if (method === 'Network.responseReceived') {
// 如果需要获取响应体内容
if (params.response.url.indexOf('/xx/xx/xx') !== -1) {
childWindow.webContents.debugger
.sendCommand('Network.getResponseBody', {
requestId: params.requestId,
})
.then((response) => {
console.log('响应体内容:', response.body);
})
.catch((err) => {
console.log('获取响应体失败:', err);
});
}
}
});
};
Electron截取响应体
Mr_Wu20182025-06-16 8:45
相关推荐
子兮曰6 小时前
async/await高级模式:async迭代器、错误边界与并发控制恋猫de小郭6 小时前
2026 Flutter VS React Native ,同时在 AI 时代 VS Native 开发,你没见过的版本GIS之路8 小时前
ArcGIS Pro 中的 Notebooks 入门IT_陈寒9 小时前
React状态管理终极对决:Redux vs Context API谁更胜一筹?Kagol10 小时前
TinyVue 支持 Skills 啦!现在你可以让 AI 使用 TinyVue 组件搭建项目柳杉10 小时前
从零打造 AI 全球趋势监测大屏simple_lau10 小时前
Cursor配置MasterGo MCP:一键读取设计稿生成高还原度前端代码睡不着先生10 小时前
如何设计一个真正可扩展的表单生成器?天蓝色的鱼鱼11 小时前
模块化与组件化:90%的前端开发者都没搞懂的本质区别明君8799711 小时前
Flutter 如何给图片添加多行文字水印