Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture screen -- chrome.desktopCapture.chooseDesktopMedia fails -- PNacl extension

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.

like image 752
jster Avatar asked Nov 17 '25 18:11

jster


1 Answers

You 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) {
                // communicate 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
    }
});
like image 69
xdumaine Avatar answered Nov 19 '25 10:11

xdumaine



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!