捕获屏幕 - chrome.desktopCapture.chooseDesktopMedia失败 - PNacl扩展 [英] Capture screen -- chrome.desktopCapture.chooseDesktopMedia fails -- PNacl extension
问题描述
我尝试按以下方式使用 desktopCapture API 。
chrome.desktopCapture.chooseDesktopMedia(
[screen,window],onAccessApproved);
当设置断点并检查它时,chrome.desktopCapture显示为未定义。清单文件中的权限如下: -
$ b
permissions:[desktopCapture,notifications]
这个API失败的常见原因列于 here
- 在应用程序的manifest.json文件中缺少权限
- API在更新版本的Chrome上定义,然后从ChromeApi继承当前运行时
文档
我没有这些问题。
- 我的Chrome版本为
43.0.2357.124 m
- 胡椒版本为43
仅供参考,我正在尝试开发Chrome扩展程序以使用PNacl捕获屏幕,并借用 media_stream_video例子下载了f rom这里。但是我甚至还没有把消息发送给pexe方面。我仍然坚持在 chrome.desktopCapture.chooseDesktopMedia
返回undefined。
您需要从在扩展的上下文中运行的后台脚本调用 chrome.desktopCapture.chooseDesktopMedia
。 本示例展示了一种使用扩展名获取屏幕的简单方法媒体。
请记住,这是基于回调的,因此您可以从回调中访问流ID。
这会在您的网页上下文中执行(请参阅完整示例此处):
//检查扩展是否安装了
if(sessionStorage.getScreenMediaJSExtensionId){
//将消息发送到请求媒体的扩展
chrome.runtime.sendMessage(sessionStorage.getScreenMediaJSExtensionId,
{type:'getScreen',id:1},null,
function(data) {
if(data.sourceId ===''){//用户取消
//处理错误
} else {
constraints.video.mandatory.chromeMediaSourceId = data.sourceId;
getUserMedia(约束,回调);
}
}
);
}
并且在你的扩展的上下文中运行(参见完整的示例 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){
// // //这个字符串到应用程序,所以它可以调用getUserMedia它
message.type ='gotScreen';
message.sourceId = streamid;
回调(消息);
返回false;
});
返回true; //保留chooseDes的回调ktopMedia结果
}
});
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.
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
}
});
这篇关于捕获屏幕 - chrome.desktopCapture.chooseDesktopMedia失败 - PNacl扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!