javascript - 如何将自定义端口条目列入白名单,以便 Chrome 提供启用相机和麦克风的选项

标签 javascript google-chrome webrtc getusermedia

我在etc/hosts文件中添加了一个自定义端口

127.0.0.1    testlocalhost.com

当从此端口启动服务器(http 而不是 https)时,我注意到 Chrome 禁止了相机和麦克风权限,并抛出

getUserMedia() no longer works on insecure origins

直接从localhost启动时,我可以更改这2个权限,尽管仍然看到您与此站点的连接不安全警告。

我想知道是否可以将自定义端口列入白名单。

谢谢!!!

(在 Firefox 中测试时,它仍然为我提供了更改相机和麦克风权限的选项。)

最佳答案

在您肯定收到的错误消息中,有一个指向 this page 的链接,其中有一段关于 Testing Powerful Features其中列举了一些选项,其中,

  1. You can run chrome with the --unsafely-treat-insecure-origin-as-secure="http://example.com" flag (replacing "example.com" with the origin you actually want to test), which will treat that origin as secure for this session. Note that on Android and ChromeOS this requires having a device with root access/dev mode. (This flag is broken in Chrome 63 but fixed in Chrome 64 and later. Prior to Chrome 62, you must also include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the flag to work.)

因此,您只需从命令行使用标志 --unsafely-treat-insecure-origin-as-secure="http://teSTLocalhost.com"启动 Chrome

关于javascript - 如何将自定义端口条目列入白名单,以便 Chrome 提供启用相机和麦克风的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55032062/

相关文章:

javascript - 为 jQuery 位置变量获取未定义

google-chrome - Google Logo 、 map 图 block 和其他 Google 图像无法在 Chrome 中加载 (HTTP 400)

google-chrome - webrtc:无法通过chrome中的数据通道发送arraybuffer

javascript - 无法在react-native android中居中对齐标题标题

javascript - javascript中prototype的使用(与constructor的对比及使用方法)

javascript - 为什么我使用 javascript 日期在浏览器中得到错误的日期?

javascript - 从 webrtc 将网络摄像头帧传递给 python opencv

javascript - http 页面调用的 https iframe 中的 getUserMedia

javascript - 删除所选行后未进行动态行删除

javascript - 使用边框颜色的 Chrome 表格 css 故障