首页 > 解决方案 > ElectronJS Windows Server 代理 PAC URL 连接超时

问题描述

由于先进的安全性和防火墙,我需要通过 Electron 应用程序的 PAC URL 代理从不接受来自外部(TCP 或 HTTP(S))的请求的服务器建立 WebSocket 连接。唯一可接受的解决方案是带有已定义PAC URL 代理的 HTTPS(端口 443)请求。我必须通过系统内的 TCP 读取数据并通过 HTTPS websocket 发送。

我选择将 ElectronJS 与 NodejS 包一起使用,一切正常,我必须连接到外部 WebSocket 服务器。我尝试了以下事情

const { app, BrowserWindow} = require('electron')
app.commandLine.appendSwitch('proxy-pac-url', 'http://someURL.com:9001/proxy.pac')
var wsUri = "wss://echo.websocket.org/";
var websocket = new WebSocket(wsUri); //works in Chrome, not in the code
this.proxyHost = 'http://someURL.com:9001/proxy.pac'
log.info('Is client ' + this.name + ' already connected: ' + this.isConnected)
  if (!this.isConnected) {
    let wsEndpoint = `ws://${this.host}:${this.port}?auth=${this.auth}`
    if (this.port == '443') {
      wsEndpoint = `wss://${this.host}:${this.port}?auth=${this.auth}`
    }

    if (this.proxyHost) {
      const options = url.parse(this.proxyHost)
      const agent = new HttpsProxyAgent(options)
      this.socket = new WebSocket(wsEndpoint, '', { agent: agent })
      log.info('Connecting client ' + wsEndpoint + ' via proxy: ' + this.proxyHost)
    } else {
      this.socket = new WebSocket(wsEndpoint)
      log.info('Connecting client ' + wsEndpoint)
    }

    return true
  }
  return false
this.proxyHost = 'http://someURL.com:9001/proxy.pac'
const { app, BrowserWindow} = require('electron')
var wsUri = "wss://echo.websocket.org/";
var win = new BrowserWindow({//some settings})
win.webContents.session.setProxy(this.proxyHost, function (e) {
    log.info(e);
    log.info('Odlicno')
    return true
  })

我不明白一切如何通过命令行工作,但无法通过应用程序代码工作。我确定我在应用程序和 Chrome 控制台中使用相同的代码

标签: node.jselectron

解决方案


推荐阅读