我在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其中列举了一些选项,其中,
- 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/