I'm trying to use the desktopCapture API in the following manner.
chrome.desktopCapture.chooseDesktopMedia(
["screen", "window"], onAccessApproved);
chrome.desktopCapture shows as undefined when I set a breakpoint and inspect it. Permissions in my manifest file are as follows:-
"permissions": ["desktopCapture", "notifications" ]
Common causes for failure of this API are listed here as
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime docs inherited from ChromeApi
And I don't have those problems.
- My Chrome version is
43.0.2357.124 m
- Pepper version is 43
FYI, I am trying to develop a Chrome extension to capture the screen using PNacl, and have borrowed from the media_stream_video example downloaded from here. But I haven't even gotten to sending a message to the pexe side yet. I'm still stuck at chrome.desktopCapture.chooseDesktopMedia
returning undefined.
I'm trying to use the desktopCapture API in the following manner.
chrome.desktopCapture.chooseDesktopMedia(
["screen", "window"], onAccessApproved);
chrome.desktopCapture shows as undefined when I set a breakpoint and inspect it. Permissions in my manifest file are as follows:-
"permissions": ["desktopCapture", "notifications" ]
Common causes for failure of this API are listed here as
- a permission is missing in the application's manifest.json file
- the API is defined on a newer version of Chrome then the current runtime docs inherited from ChromeApi
And I don't have those problems.
- My Chrome version is
43.0.2357.124 m
- Pepper version is 43
FYI, I am trying to develop a Chrome extension to capture the screen using PNacl, and have borrowed from the media_stream_video example downloaded from here. But I haven't even gotten to sending a message to the pexe side yet. I'm still stuck at chrome.desktopCapture.chooseDesktopMedia
returning undefined.
- what's happening - error message, stream invalid? – Amit G Commented Jun 18, 2015 at 5:46
- another way to capture current visible tab developer.chrome./extensions/tabs#method-captureVisibleTab – Amit G Commented Jun 18, 2015 at 5:47
- The exact error logged in Console is -- "Uncaught TypeError: Cannot read property 'chooseDesktopMedia' of undefined" Essentially this statement doesn't work 'chrome.desktopCapture.chooseDesktopMedia( "screen", "window"], onAccessApproved);' because chrome.desktopCapture shows as undefined.. From that it feels like the permission to capture the screen "desktopCapture" has not been granted. – jster Commented Jun 18, 2015 at 6:06
- @AmitG - from the description of captureVisibleTab, it seems like its used for image capture.. I'm trying to record the screen and save it to a Chrome file (I understand that I can't access the local filesystem from an extension, but that I can store to a "Chrome file"). – jster Commented Jun 18, 2015 at 6:11
- 1 You forgot another failure condition. Most APIs are not available from content scripts. Is that your problem? Also, your question has nothing to do with NaCl side of things, you may want to edit that out as it's irrelevant. – Xan Commented Jun 18, 2015 at 9:07
1 Answer
Reset to default 1You need to call chrome.desktopCapture.chooseDesktopMedia
from the background script running in the context of the extension. This Sample shows a simple method to use the extension to get screen media.
Keep in mind that this is callback based, so you get access to the stream id from the callback.
This runs in the context of your page (see full example here):
// check that the extension is installed
if (sessionStorage.getScreenMediaJSExtensionId) {
// send a message to your extension requesting media
chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
{type:'getScreen', id: 1}, null,
function (data) {
if (data.sourceId === '') { // user canceled
// handle error
} else {
constraints.video.mandatory.chromeMediaSourceId = data.sourceId;
getUserMedia(constraints, callback);
}
}
);
}
And this run in the context of your extension (see full example here):
chrome.runtime.onMessageExternal.addListener(function (message, sender, callback) {
switch(message.type) {
case 'getScreen':
var pending = chrome.desktopCapture.chooseDesktopMedia(message.options || ['screen', 'window'],
sender.tab, function (streamid) {
// municate this string to the app so it can call getUserMedia with it
message.type = 'gotScreen';
message.sourceId = streamid;
callback(message);
return false;
});
return true; // retain callback for chooseDesktopMedia result
}
});