1 Star 0 Fork 0

陈东宇/electron-session-proxy

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Electron设置webview代理

运行项目

  1. 安装依赖

    npm install
    
  2. 运行

    npm run start
    
  3. 运行效果

原理

electron本身的session不支持代理认证,我们可以中间转接一层,先开启一个支持认证的socks5客户端将数据从socks5代理服务端里面拿过来,再在本地起一个http代理服务端,我们将这个本地http代理服务设置到electron的session里面去,这样数据就能通过socks5客户端 --> http本地服务端 --> electron session。

下面是我实际应用的一个示例

这样就可以不安装vpn,使用electron设置代理通过webview访问到现场的内网网页

注意事项

现场网页必须是https的!否则无法触发代理认证!!!

如果内网网页是http的,可以通过openssl生成自签名证书,通过nginx反向代理设置证书地址,开放443端口支持https

下面是我nginx设置的一个例子,可以同时支持https和http

server {
        listen  80;
        server_name 10.8.0.126 10.10.112.5 127.0.0.1;
        location / {
                proxy_pass http://127.0.0.1:9092;
                proxy_redirect off;
                root /home/narada/ems/www/;
                index index.html;
        }
        location /favicon.ico {
                root    /home/narada/ems/www/dist;
        }
        location /static/ {
                root    /home/narada/ems/www/dist;
        }
}

server {
        listen 443 ssl;
        server_name 10.8.0.126 10.10.112.5 127.0.0.1;

        ssl_certificate /home/narada/crt/server.crt;
        ssl_certificate_key /home/narada/crt/server.key;

        location / {
            proxy_pass http://127.0.0.1:9092;
            proxy_redirect off;
            root /home/narada/ems/www/;
            index index.html;
        }

        location /favicon.ico {
                root    /home/narada/ems/www/dist;
        }
        location /static/ {
                root    /home/narada/ems/www/dist;
        }

}

参考资料:https://github.com/MissGwen/electron-session-proxy

使用方法

  1. 使用socks5代理

    const { session } = require("electron");
    const { sockProxyRules } = require('./proxy/socksProxy/socksProxy');
    
    const ses = session.defaultSession;
    const proxyRules = await sockProxyRules("[socks4/5]://[userId]:[password]@[host]:[port]");
    ses.setProxy({ proxyRules: proxyRules.url });
    
  2. 使用http代理

    const { session } = require("electron");
    const { httpProxyRules } = require('./proxy/httpProxy/httpProxy');
    
    const ses = session.defaultSession;
    const proxyRules = await httpProxyRules("[http]://[userId]:[password]@[host]:[port]");
    ses.setProxy({ proxyRules: proxyRules.url });
    

空文件

简介

electron使用带身份认证的代理访问webview,支持socks5、http代理 展开 收起
取消

发行版

暂无发行版

贡献者 (1)

全部

近期动态

2个月前推送了新的提交到 master 分支,9a4ede1...9c6c069
2个月前推送了新的提交到 master 分支,9b23c60...9a4ede1
2个月前推送了新的 master 分支
2个月前创建了仓库
不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen-dongyu123/electron-session-proxy.git
git@gitee.com:chen-dongyu123/electron-session-proxy.git
chen-dongyu123
electron-session-proxy
electron-session-proxy
master

搜索帮助