2

Using interceptBufferProtocol, I can successfully intercept the loadURL event to https://google.com mainWindow.loadURL("https://google.com/"); and replace it with my custom HTML code. The HTML code has an iframe which I am trying to proxy. This can usually be achieved by setting the electron browserWindow proxy but in my case, it fails to work. I set the proxy with the following code:

mainWindow.webContents.session.setProxy({
                proxyRules: "http://" + proxy
            }, () => {
                console.log('Proxy: http://' + proxy)
        }) 

Intercept url code:

ses.protocol.interceptBufferProtocol('https', (req, callback) => {
ses.resolveProxy(req.url, (x) => {
    console.log(x)
})
if (req.url == "https://google.com/") {
    fs.readFile(path.join(__dirname, "/../../path/stuff.html"), 'utf8', function(err, html) {
        callback(Buffer.from(html, 'utf8'));
    });
} else {
    const request = net.request(req)
    request.on('response', res => {
        const chunks = []

        res.on('data', chunk => {
            chunks.push(Buffer.from(chunk))
        })

        res.on('end', async () => {
            const file = Buffer.concat(chunks)
            callback(file)
        })
    })

    if (req.uploadData) {
        req.uploadData.forEach(part => {
            if (part.bytes) {
                request.write(part.bytes)
            } else if (part.file) {
                request.write(fs.readFileSync(part.file))
            }
        })
    }
    request.end()
}

})

However, no matter what I do, it appears to use my local IP instead of a proxy. Do I have any options?

The code runs fine without a proxy. I'm trying to run it with one. The problem lies within the .interceptBufferProtocol() function. Any help would be appreciated!

Jeff
  • 170
  • 2
  • 5
  • 19

0 Answers0