我試圖在Chrome瀏覽器中使用navigator.getUserMedia;但是,在本地提供服務時(文件:///whatever/index.html),它並不請求許可,但在JSFiddle(http://jsfiddle.net/EBsvq/)和其他站點上提供。Chrome getUserMedia本地不請求權限
有誰知道這個的原因?我是否需要以某種方式重置我的權限?
下面是我使用本地:
<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>
這是正確的:getUserMedia只適用於從服務器上的文件運行。它不會從file:// URLs工作。你會得到'PERMISSION_DENIED:1'錯誤,但這不是很直觀! –
@SamDutton:我提交了一個錯誤報告,要求提供更直觀的錯誤消息:https://code.google.com/p/chromium/issues/detail?id=257104 – Gili
@Gili:starred! –