有什么办法可以拦截BrowserWindow
主进程中的http响应主体没有调试器?
是否无法使用WebRequest
类和onCompleted
method?
我可以使用调试器做到这一点,但由于某种原因我不能使用它
await w.webContents.debugger.sendCommand('Network.enable')
w.webContents.debugger.on('message', async (event, method, params) => {
if (method === 'Network.dataReceived') {
const responseBody = await w.webContents.debugger.sendCommand('Network.getResponseBody', {requestId: params.requestId})
}
})
UPD
我只找到一种解决方案debugger
。它并不完美????,但它解决了我的问题。
Use webPreference.preload
注入这个猴子补丁脚本。
let oldXHROpen = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
this.addEventListener('load', function() {
console.log('data: ' + this.responseText);
});
return oldXHROpen.apply(this, arguments);
}
console.log
可以用 ipc 替换来将此数据发送到主进程