Search code examples
javascriptgoogle-chromehttpswebcamwebrtc

chrome doesn't give access to web camera


The test code:

<!doctype html>
<html>
<body>
<video id="v1" autoplay="autoplay"></video>
<script>
navigator._getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator._getUserMedia({video: true}, function(stream) {
    document.getElementById('v1').src = URL.createObjectURL(stream);
}, function() {});
</script>
</body>
</html>

chrome34.0.1847.116 m doesn't give access to web camera if the page is opened over http, but it works if opened over https. That is, the web camera icon (image from google) appears in address bar. I click it, select "Ask if example.com wants to access your camera", click "Done", then "Reload" in a bar that appears. But the video doesn't appear. It works right from the start if opened over https.

The webcamera is Logitech C210. It works fine in skype. Any thoughts?


Solution

  • Are you sure it's not because you are trying to open your page directly from the file, not from a webserver and thus with a file:/// prefix and not a http(s):// one ?

    If the url in the bar address looks like file:///... then chrome will not allow access to the camera.

    However if you launch your page through a basic webserver (python -m SimpleHTTPServer in the folder where your page is) or with JSFiddle (http://jsfiddle.net/7Hkws/), it works perfectly fine.


    In chrome settings, Privacy > Content Settings > Medias should be set to Ask when a site requires access to your camera and microphone (recommended)