Chrome getUserMedia本地不请求权限 [英] Chrome getUserMedia Not Requesting Permission Locally

查看:605
本文介绍了Chrome getUserMedia本地不请求权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Chrome浏览器中使用navigator.getUserMedia;然而,它不是在本地服务时请求权限(file:///whatever/index.html),而是在JSFiddle上( http://jsfiddle.net/EBsvq/ )和其他网站。



有谁知道这个的原因?我需要以某种方式重置我的权限?



以下是我在本地使用的内容:

 < HTML> 
< head>< / head>
< body>
< button id =btn>开始< / button>

< script type =text / javascript>
/ *! jQuery v1.8.3 jquery.com | jquery.org/license * /
// JQuery去这里
< / 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屏蔽了 file:/// 不报告安全性错误的URI(例如,地理位置)。您最好的选择是从本地网络服务器运行,如果您安装了Python,请尝试 SimpleHTTPServer


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.

这篇关于Chrome getUserMedia本地不请求权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆