Chrome is not letting HTTP hosted site to access Camera & Microphone

送分小仙女□ 提交于 2021-02-10 11:56:50

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/47995355/chrome-is-not-letting-http-hosted-site-to-access-camera-microphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!