Chrome.tabCapture.capture returned stream undefined

I have js code in the chrome background extension from the following:

function handleCapture(stream) { console.log('content captured'); console.log("backround.js stream: ", stream); alert(stream); // localStream = stream; // used by RTCPeerConnection addStream(); // initialize(); // start signalling and peer connection process } function captureCurrentTab() { console.log('reqeusted current tab'); chrome.tabs.getSelected(null, function(tab) { console.log('got current tab'); var selectedTabId = tab.id; chrome.tabCapture.capture({ audio : false, video : true }, handleCapture); }); } 

However, when this is executed, is the variable "handleCapture" "stream" that is being transferred always undefined? Is this to be expected, or is there something I miss here?

In addition, I confirmed that my manifest.json contains capture permission, and I am using Version 31.0.1607.1 canary Aura chrome canary.

Thanks Mike

+4
source share
2 answers

You should probably provide some restrictions to make it work. See: http://developer.chrome.com/extensions/tabCapture.html#type-MediaStreamConstraint

The capture parameter you presented is MediaTrackConstraint, see http://dev.w3.org/2011/webrtc/editor/getusermedia.html#mediastreamconstraints

which is also a simple JS object where you must set some required parameters, see http://dev.w3.org/2011/webrtc/editor/getusermedia.html#idl-def-MediaTrackConstraints

So, if you install all the necessary settings in a required object, this should help the following:

 chrome.tabCapture.capture({ audio : false, video : true, { mandatory: { width: { min: 640 }, height: { min: 480 } } } }, handleCapture); 
+1
source

I had the same problem when I tried to control tabCapture exclusively from a background script, I found this on the tabCapture man page:

Capture the visible area of ​​the active tab. This method can only be used on the current active page after the extension has been called , similar to how activeTab works. Please note that Chrome internal pages cannot be captured.

I understand that this means that you need to bring it out of the browser for your extension, for example:

 chrome.browserAction.onClicked.addListener(function(request) { chrome.tabs.getSelected(null, function(tab) { chrome.tabCapture.capture({audio: true, video: true}, callback); }); }); 

What worked for me.

+1
source

Source: https://habr.com/ru/post/1498292/


All Articles