首页 > 解决方案 > 电子远程网址显示不支持浏览器

问题描述

我对节点和电子很陌生。我在这里关注电子简单应用程序示例以访问远程 URL https://core1-den.brightlinkip.com/webphone/

我似乎无法弄清楚如何让它识别电子正在运行有效的浏览器。它一直给我一个错误“不支持浏览器”。该网站在 Chrome 上可以正常打开。

我也尝试在电子上手动设置用户代理,但仍然显示相同的错误,“不支持浏览器”

这是电子上的默认用户代理:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Electron/8.2.1 Safari/537.36

这是我的用户代理:

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36

这是我的代码:

const {app, BrowserWindow} = require('electron') // http://electron.atom.io/docs/api

let window = null

// Wait until the app is ready
app.once('ready', () => {
  // Create a new window
  window = new BrowserWindow({
    // Set the initial width to 800px
    width: 800,
    // Set the initial height to 600px
    height: 600,
    // Don't show the window until it ready, this prevents any white flickering
    show: false,
    webPreferences: {
      // Disable node integration in remote page
      nodeIntegration: false
    }
  })

  // URL is argument to npm start
  const url = "https://core1-den.brightlinkip.com/webphone/"
  window.loadURL(url)

  // Show window when page is ready
  window.once('ready-to-show', () => {
    window.maximize()
    window.show()
  })
})

我认为来自远程 url 的浏览器检测代码是相关的:

detectBrowser: function(e) {
            var t = e && e.navigator
              , n = {};
            if (n.browser = null,
            n.version = null,
            void 0 === e || !e.navigator)
                return n.browser = "Not a browser.",
                n;
            if (t.mozGetUserMedia)
                n.browser = "firefox",
                n.version = r(t.userAgent, /Firefox\/(\d+)\./, 1);
            else if (t.webkitGetUserMedia)
                n.browser = "chrome",
                n.version = r(t.userAgent, /Chrom(e|ium)\/(\d+)\./, 2);
            else if (t.mediaDevices && t.userAgent.match(/Edge\/(\d+).(\d+)$/))
                n.browser = "edge",
                n.version = r(t.userAgent, /Edge\/(\d+).(\d+)$/, 2);
            else {
                if (!e.RTCPeerConnection || !t.userAgent.match(/AppleWebKit\/(\d+)\./))
                    return n.browser = "Not a supported browser.",
                    n;
                n.browser = "safari",
                n.version = r(t.userAgent, /AppleWebKit\/(\d+)\./, 1)
            }

标签: node.jselectron

解决方案


推荐阅读