未捕获的类型错误:无法执行“webkitGetUserMedia”在“导航器”上:必须至少请求音频和视频之一
我正在尝试通过我正在构建的 Chrome 扩展程序在 Chrome 浏览器中对页面进行简单的音频视频捕获。我正在内容脚本中运行以下代码。
我不明白为什么它很难接受我的配置,我已经包含了音频和视频,但它仍然抱怨这
Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': At least one of audio and video must be requested
at chooseDesktopMedia
是我尝试过的代码:
chooseDesktopMedia();
function chooseDesktopMedia(){
navigator.webkitGetUserMedia(
["screen"]
, function onSuccess(stream) {
showScreenShare(
{
audio: true,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: streamId
}
}
}
);
}, function onError(e) {
console.error(e);
alert('Failed to get user media.');
});
}
function showScreenShare(conf){
var ve = document.getElementById("screen-share");
navigator.mediaDevices.getUserMedia(conf)
.then(function(stream){
var url = window.URL.createObjectURL(stream);
ve.src = url;
})
.catch(function(e){
console.log(e);
alert(e);
});
}
I am trying to do a simple audio video capture of the page in Chrome browser via chrome extension I am building. I am running the following code in a content script.
I don't understand why it is struggling to accept my config, I've included both audio and video yet it still complains that
Uncaught TypeError: Failed to execute 'webkitGetUserMedia' on 'Navigator': At least one of audio and video must be requested
at chooseDesktopMedia
here is the code I tried:
chooseDesktopMedia();
function chooseDesktopMedia(){
navigator.webkitGetUserMedia(
["screen"]
, function onSuccess(stream) {
showScreenShare(
{
audio: true,
video: {
mandatory: {
chromeMediaSource: 'desktop',
chromeMediaSourceId: streamId
}
}
}
);
}, function onError(e) {
console.error(e);
alert('Failed to get user media.');
});
}
function showScreenShare(conf){
var ve = document.getElementById("screen-share");
navigator.mediaDevices.getUserMedia(conf)
.then(function(stream){
var url = window.URL.createObjectURL(stream);
ve.src = url;
})
.catch(function(e){
console.log(e);
alert(e);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不认为有类似的东西
,或者也许我对此一无所知,但它的意思是什么
,因为在 getUserMedia 中,您没有定义音频或视频的约束,这应该像这样
Screen Capture
另一方面,要运行屏幕捕获,您将使用 getDisplayMedia() 访问 Screen Capture API,不是 getUserMedia()
因为权限策略,我无法在 SO 片段中运行示例,但是您可以尝试执行此操作,复制下面的代码,在开发人员工具中打开控制台,然后运行此
*免责声明: 自己跑 风险
I don't think there is something like
or maybe I'm ignorant about it, but what it meant by
because in your getUserMedia, you didn't define the constraints with either audio or video, which should be like this
Screen Capture
On the other hand, to run screen capture, you will access Screen Capture API with getDisplayMedia(), not getUserMedia()
because of permission policy, I can't run example in SO snippets, but what you can do to try this, copy the code below, open your console in developer tools, then run this
*disclamer: run at your own risk