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>
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.
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.
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With