Is there some way to intercept BrowserWindow
http response body in main process without debugger?
Is it impossible to use WebRequest
class and onCompleted
method?
I can do that with debugger but for some reason I can not use this
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
I found only one solution expect debugger
. It is not perfect but it solve my issue.
Use webPreference.preload
to inject this monkey patching script.
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
may be replaced with ipc to send this data to main process