从电子获取代理设置 [英] Getting proxy settings from electron

查看:77
本文介绍了从电子获取代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在系统中设置代理设置时,我的Electron应用程序会自动将其用于常见请求(axios程序包),而不是用于websockets(socket.io-client程序包)。如果我手动提供代理设置,那么websockets也将开始工作,但是我想避免手动配置,因为这对于实际应用的用户来说可能比较棘手。因此,我正在寻找通过电子方式获取代理设置并将其传输到网络套接字的任何方法。

When i set proxy settings in the system my Electron application gets it automatically for common requests (axios package), but not for websockets (socket.io-client package). If i provide proxy settings manually then websockets starts to work too, but i want to try to avoid manual configuration, because it may be tricky to the real app's users. So i'm looking any way to get proxy settings from electron and transfer them to the websockets.

我尝试在主浏览器和主浏览器中都使用login事件渲染器进程,但它根本不会触发。有没有办法获取电子使用的代理设置?

I have tried to use login event for my browserWindow in the both main and renderer process, but it doesn't trigger at all. Is there any way to get proxy settings that electron uses?

推荐答案

我找到了解决方案。可以在主进程内部进行代理设置。

I've found the solution. It's possible to take proxy-settings inside the main process.

mainWindow = new BrowserWindow({})
const ses = mainWindow.webContents.session;
ses.resolveProxy('url_you_need_to_achieve', (proxy) => {
    // do whatever you want with proxy string, that contains proxy-setting
});

这篇关于从电子获取代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆