如何将自定义端口条目列入白名单,以便 Chrome 提供启用摄像头和麦克风的选项
How to whitelist custom port entry so Chrome offers the options to enable Camera and Mic
我在 etc/hosts 文件中添加了自定义端口
127.0.0.1 testlocalhost.com
从这个端口启动服务器(http 而不是 https)时,我注意到 Chrome 禁止了摄像头和麦克风权限,并抛出了
getUserMedia() no longer works on insecure origins
直接从 localhost
启动时,我可以更改这 2 个权限,但仍然会看到 Your connection to this site is not secure
警告。
我想知道是否可以将自定义端口列入白名单。
谢谢!!!
(在 Firefox 中测试时,它仍然为我提供了更改摄像头和麦克风权限的选项。)
简短的回答是否定的 - 你不能用代表它的 IP 地址绕过保存的词 localhost
。原因是 Google Chrome 使用实际词 localhost
来检测开发者调试并允许通过 HTTP 使用 getUserMedia
。所有其他地址,无论它们是否代表 localhost
,都只允许通过 HTTPS 或 WSS 使用 getUserMedia
。
在你肯定有的错误信息中,有一个link到this page, where there is a paragraph about 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
像上面post回答的那样,我可以运行 chrome在搜索栏中通过chrome://flags/
标记,搜索标记:insecure origins treated as secure
,启用它,并在那里添加您的自定义端口,用 ,
分隔
我在 etc/hosts 文件中添加了自定义端口
127.0.0.1 testlocalhost.com
从这个端口启动服务器(http 而不是 https)时,我注意到 Chrome 禁止了摄像头和麦克风权限,并抛出了
getUserMedia() no longer works on insecure origins
直接从 localhost
启动时,我可以更改这 2 个权限,但仍然会看到 Your connection to this site is not secure
警告。
我想知道是否可以将自定义端口列入白名单。
谢谢!!!
(在 Firefox 中测试时,它仍然为我提供了更改摄像头和麦克风权限的选项。)
简短的回答是否定的 - 你不能用代表它的 IP 地址绕过保存的词 localhost
。原因是 Google Chrome 使用实际词 localhost
来检测开发者调试并允许通过 HTTP 使用 getUserMedia
。所有其他地址,无论它们是否代表 localhost
,都只允许通过 HTTPS 或 WSS 使用 getUserMedia
。
在你肯定有的错误信息中,有一个link到this page, where there is a paragraph about 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"
像上面post回答的那样,我可以运行 chrome在搜索栏中通过chrome://flags/
标记,搜索标记:insecure origins treated as secure
,启用它,并在那里添加您的自定义端口,用 ,