node.js - 电子远程网址显示不支持浏览器
问题描述
我对节点和电子很陌生。我在这里关注电子简单应用程序示例以访问远程 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)
}
解决方案
推荐阅读
- java - AWS SqsListener 使用 Jackson 反序列化自定义对象
- c++ - 是否需要遍历 boost rtree 的层次结构才能达到最大效率?
- autocomplete - 您可以将自动完成结果分成两个输入字段吗?
- python - 将字节解码为 ascii 字符串
- ruby-on-rails - 规范中的 ActiveStorage 文件:ActiveRecord::LockWaitTimeout
- java - 应用程序关闭时出现空指针异常
- python - 为什么从 python 子进程写入继承的文件句柄会导致并非所有行都被写入?
- heroku - 自定义域重定向到 Heroku 域,而不是充当别名
- r - 通过粘贴从基于值的子集中提取的行来构建表
- javascript - 从Android webView单击按钮提交不起作用