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);
});
}