Hi all,
I'm developing an Electron application that uses the http-mitm-proxy library for intercepting and handling web requests. My application is set up to create a custom proxy to intercept web traffic. So far, I've successfully managed to intercept HTTP traffic, but I'm encountering issues when trying to intercept HTTPS traffic.
The core problem seems to be that while HTTP requests are handled perfectly, HTTPS requests are not going through as expected. After some research and debugging, I've concluded that the likely culprit is the SSL certificate: it appears I need to install or trust the SSL certificate generated by http-mitm-proxy within the Electron browser for HTTPS interception to work correctly but how ?
Below is the full code snippet of my current setup:
function createWindowWithProxy(proxyConfig, windowTitle) {
const proxyURL = `http://${proxyConfig.ip}:${proxyConfig.port}`;
const ses = session.fromPartition(windowTitle, { cache: false });
ses.setProxy({
proxyRules: proxyURL,
proxyBypassRules: "localhost,*.local"
}).then(() => {
let win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
session: ses,
nodeIntegration: true,
contextIsolation: false,
preload: path.join(__dirname, 'preload.js')
},
title: windowTitle,
show: false
});
win.loadURL('https://www.google.com');
win.on('closed', function () {
win = null;
});
});
}
app.on('ready', () => {
const proxyConfig = {
ip: 'localhost',
port: 8084
};
const windowTitle = 'persist:proxySession';
createWindowWithProxy(proxyConfig, windowTitle);
setupProxy(proxyConfig.port);
});
function setupProxy(port) {
const proxy = new Proxy();
proxy.listen({ port: port });
proxy.onRequest((ctx, callback) => {
return callback();
});
}