Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome getUserMedia Not Requesting Permission Locally

I'm attempting to play around with navigator.getUserMedia in Chrome; however, it is not requesting permission when served locally (file:///whatever/index.html), but does on JSFiddle ( http://jsfiddle.net/EBsvq/ ) and other sites.

Does anyone know the reason for this? Do I need to somehow reset my permissions?

Here is what I am using locally:

<html>
<head></head>
<body>
   <button id="btn">Start</button>

<script type="text/javascript">
   /*! jQuery v1.8.3 jquery.com | jquery.org/license */
   //JQuery goes here
</script>

<script type="text/javascript">
  navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;

  $(function(){
    $('#btn').click(function(){
      navigator.getUserMedia({audio: true}, 
      function(){
        alert('success');
      },
      function (err) {
        alert('fail: ' + JSON.stringify(err));
      }); }); });
      </script>
  </body>
</html>
like image 345
TomJ Avatar asked Dec 05 '12 12:12

TomJ


3 Answers

Chrome blocks a lot of stuff on file:/// URIs without reporting a security error (eg. Geolocation). Your best option is to run from a local webserver, if you have Python installed try SimpleHTTPServer.

like image 184
robertc Avatar answered Nov 11 '22 06:11

robertc


You can use the --allow-file-access-from-files flag from the command line when opening chrome to be able to use getUserMedia from a local file system.

like image 25
Alejandro Silva Avatar answered Nov 11 '22 06:11

Alejandro Silva


I encountered similar problem, but related to microphone access. Chrome blocks device access if you serve your file via file://(note that on Microsoft Edge and Firefox it worked via file:://).

One solution i've found for Chrome:

  1. open chrome an type in the URL chrome://version/
  2. copy the value of "Command Line" field in your command line and append --allow-file-access-from-files and run it
  3. after Chrome opened and enter your file:// url.

For starting Chrome always like that, right click on Chrome icon, and then click on properties. In the Shortcut tab append to the Target value all the command line parameters from 2.

like image 1
ancab Avatar answered Nov 11 '22 05:11

ancab