最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome is not letting HTTP hosted site to access Camera & Microphone - Stack Overflow

programmeradmin6浏览0评论

I'm using react-webcam to capture a selfie for an application. On localhost, react-webcam works perfectly whereas on HTTP hosted web server camera access is being denied by default on the Chrome. Is there any workaround for webcam access or any other npm plugin which can serve the purpose here.

NOTE: HTTPS supported sites are allowed to access both the Camera & Microphone. Here, I'm left with only HTTP choice.

I'm using react-webcam to capture a selfie for an application. On localhost, react-webcam works perfectly whereas on HTTP hosted web server camera access is being denied by default on the Chrome. Is there any workaround for webcam access or any other npm plugin which can serve the purpose here.

NOTE: HTTPS supported sites are allowed to access both the Camera & Microphone. Here, I'm left with only HTTP choice.

Share Improve this question asked Dec 27, 2017 at 16:18 Ankita GoyalAnkita Goyal 5511 gold badge3 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 13

If you are using this for a development environment and want to test it on your phone you can do the following:

  • Go to: chrome://flags/#unsafely-treat-insecure-origin-as-secure
  • Enable `Insecure origins treated as secure`
  • Add the addresses for which you want to ignore this policy
  • Restart chrome

The react-webcam uses the getUserMedia API which specification states:

When on an insecure origin [mixed-content], User Agents are encouraged to warn about usage of navigator.mediaDevices.getUserMedia, navigator.getUserMedia, and any prefixed variants in their developer tools, error logs, etc. It is explicitly permitted for User Agents to remove these APIs entirely when on an insecure origin, as long as they remove all of them at once (e.g., they should not leave just the prefixed version available on insecure origins).

Chrome, starting from version 47 implements this security policy (Source):

Starting with Chrome 47, getUserMedia() requests are only allowed from secure origins: HTTPS or localhost.

So you can't access Microphone or Camera without a secure connection.

发布评论

评论列表(0)

  1. 暂无评论