javascript 如何允许 Chrome 在本地主机上访问我的相机?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16835421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to allow Chrome to access my camera on localhost?
提问by Methuz Kaewsai-kao
I cloned a project about real-time image processing on a web browser from this link: Then I could not allow my browser to access my camera. I got this javascript alert:
我从此链接克隆了一个关于在 Web 浏览器上进行实时图像处理的项目:然后我无法允许我的浏览器访问我的相机。我收到了这个 javascript 警报:
Uh-oh, the webcam didn't start. Do you have a webcam? Did you give it permission? Refresh to try again. And the allow button is not shown as if I access his site.
呃,网络摄像头没有启动。你有网络摄像头吗?你给它许可了吗?刷新以重试。并且没有显示允许按钮,就像我访问他的网站一样。
采纳答案by Hanxue
Are you accessing the webpage that is served over HTTP, on localhost? If you are accessing it from http://localhost/..., Chrome will ask for your permission to use the camera.
您是否在本地主机上访问通过 HTTP 提供的网页?如果您从 访问它http://localhost/...,Chrome 会要求您获得使用相机的许可。


If you are opening the web page directly, i.e. /Users/Methuz/Documents/index.html then it will not work, even if you explicitly allows it permission
如果您直接打开网页,即 /Users/Methuz/Documents/index.html 那么它不会工作,即使您明确允许它的权限


In this case, the workaround I use is to host the HTML file on a webserver. A quick hack is to use python, in the folder where the HTML page is lcoated: python -m SimpleHTTPServer
在这种情况下,我使用的解决方法是将 HTML 文件托管在网络服务器上。一个快速的技巧是在 HTML 页面被 lcoated 的文件夹中使用 python:python -m SimpleHTTPServer
回答by Erik Petersen
Step 1: Find your chrome preferences file: http://www.forensicswiki.org/wiki/Google_Chrome#Configuration
第 1 步:找到您的 chrome 首选项文件:http: //www.forensicswiki.org/wiki/Google_Chrome#Configuration
Step 2: Open it and Find the "profile" key
第 2 步:打开它并找到“配置文件”键
Step3: Under profile there will be a "content_settings" hash, that will have a "pattern_pairs" hash Add this to it:
步骤 3:在配置文件下会有一个“content_settings”散列,它将有一个“pattern_pairs”散列添加到它:
"*,*": {
"media-stream-camera": 1
}
Final example:
最后一个例子:
"profile": {
....
"content_settings": {
....
"pattern_pairs": {
"*,*": {
"media-stream-camera": 1
},
....
}
}
}
WARNING: This will allow all websites access to your camera
警告:这将允许所有网站访问您的相机
回答by effe
Chrome now only allows https://servers to persistent list (version 39.xx)
Chrome 现在只允许https://服务器持久化列表(版本 39.xx)
https://support.google.com/chrome/answer/2693767?hl=en
https://support.google.com/chrome/answer/2693767?hl=en
Allow: This allows the site to access your camera and microphone at this time and a notification will appear confirming that you've granted access. If you select Allow on a "http" URL your preference will not be remembered in future visits. If you select Allow on a "https" URL, your preference will be remembered in future visits.
允许:这允许站点此时访问您的摄像头和麦克风,并且会出现一条通知,确认您已授予访问权限。如果您在“http”URL 上选择允许,您的偏好将不会在以后的访问中被记住。如果您在“https” URL 上选择允许,您的偏好将在以后的访问中被记住。
Maybe this link helps to set your local secure server if you are using Wamp. http://forum.wampserver.com/read.php?2,32986
如果您使用 Wamp,此链接可能有助于设置您的本地安全服务器。 http://forum.wampserver.com/read.php?2,32986
Then you can add your local server to persistent allow list of chrome.
然后,您可以将本地服务器添加到 chrome 的持久允许列表中。
回答by DKR
To ignore Chrome's secure origin policy, follow these steps.
要忽略 Chrome 的安全来源政策,请按照以下步骤操作。
Navigate to chrome://flags/#unsafely-treat-insecure-origin-as-securein Chrome.
chrome://flags/#unsafely-treat-insecure-origin-as-secure在 Chrome 中导航到。
Find and enable the Insecure origins treated as securesection (see below).
找到并启用该Insecure origins treated as secure部分(见下文)。
Add any addresses you want to ignore the secure origin policy for. Remember to include the port number too (if required).
添加要忽略其安全源策略的任何地址。请记住也包括端口号(如果需要)。
Save and restart Chrome.
保存并重新启动 Chrome。
I found solution from below link.Hope it will help to someone
我从下面的链接中找到了解决方案。希望它对某人有所帮助
回答by Victor Timoftii
Got this problem for days, only this helped:
好几天都遇到这个问题,只有这有帮助:
Reinstall Chrome by removing configuration as well. And try not to sync all the extensions, as they may interfere.
通过删除配置重新安装 Chrome。并尽量不要同步所有扩展,因为它们可能会干扰。
sudo apt-get purge google-chrome-stable
rm -rf ~/.config/google-chrome
Then install from official.
然后从官方安装。
回答by ZimaXXX
Another solution is to use iframetag. Jest deploy your page on server (localhost or external) and include it in your local html.
Example:
另一种解决方案是使用iframe标签。Jest 在服务器(本地主机或外部)上部署您的页面并将其包含在您的本地 html 中。例子:
<iframe src="http://localhost/your_project/index.html"></iframe>
回答by quaidj
Chrome on HTTP or any other port won't save the preference of Camara share choice.
HTTP 或任何其他端口上的 Chrome 不会保存 Camara 共享选择的首选项。
To save the selection you will need to run on HTTPs, even if you don't have SSL certificate on localhost that fine. Just add https before the localhost url and it will ask you its unsafe, if you want to proceed add it as an exception under Advance options. Do that and then Chrome will save you camera sharing preference for this website. and won't ask you to select allow
要保存选择,您需要在 HTTPs 上运行,即使您在 localhost 上没有 SSL 证书也很好。只需在 localhost url 之前添加 https ,它会询问您是否不安全,如果您想继续将其添加为高级选项下的例外。这样做,然后 Chrome 将为您保存该网站的相机共享首选项。并且不会要求您选择允许
回答by gal007
You can choose a different default permission setting and manage exceptions in Content settings.
您可以选择不同的默认权限设置并在内容设置中管理例外。
- Click the Chrome menu Chrome menu on the browser toolbar.
- Select Settings.
- Click Show advanced settings.
- In the "Privacy" section, click Content settings.
- In the "Media" section:
- 单击浏览器工具栏上的 Chrome 菜单 Chrome 菜单。
- 选择设置。
- 单击显示高级设置。
- 在“隐私”部分,单击内容设置。
- 在“媒体”部分:
*Ask me when a site requires access to my camera and microphone: Select this option if you want Chrome to alert you whenever a site requests access to your camera and microphone.
*当网站需要访问我的摄像头和麦克风时询问我:如果您希望 Chrome 在网站请求访问您的摄像头和麦克风时提醒您,请选择此选项。
*Do not allow sites to access my camera and microphone: Select this option to automatically deny any site requests to access your camera and microphone.
*不允许站点访问我的摄像头和麦克风:选择此选项可自动拒绝任何站点访问您的摄像头和麦克风的请求。
Or click Manage exceptions to remove previously-granted permissions for specific sites. Source: https://support.google.com/chrome/answer/2696491?hl=en
或者单击“管理例外”以删除先前授予的特定站点的权限。来源:https: //support.google.com/chrome/answer/2696491?hl=en
P/D: the link you provided has an error. I can't access.
P/D:您提供的链接有错误。我无法访问。
回答by monir
Open localhost/webcam.swf then right click on the flash file then allow the webcam and tick remember that will add exception for localhost
打开 localhost/webcam.swf 然后右键单击 flash 文件然后允许网络摄像头并勾选记住这将为 localhost 添加例外

