chrome.tabCapture.capture返回的流未定义 [英] chrome.tabCapture.capture returned stream is undefined

查看:947
本文介绍了chrome.tabCapture.capture返回的流未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数handleCapture(stream){
console.log('content captured');
console.log(backround.js stream:,stream);
alert(stream);
// localStream = stream; //由RTCPeerConnection addStream()使用;
// initialize(); //开始信令和同级连接过程


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

然而,当这个运行时,handleCapture变量流传入的内容始终未定义?这是预期的还是有什么,我在这里失踪?



另外,我已确认我的manifest.json包含捕获权限,我正在使用chrome Canary版本31.0.1607.1 canary Aura。



感谢,
Mike

解决方案

div>

当我尝试纯粹从后台脚本驱动tabCapture时,发生了同样的问题,我在 tabCapture 参考页面:


捕获当前活动选项卡的可见区域。此方法只能在扩展调用之后的当前活动页面上使用,类似于activeTab的工作方式。请注意,无法捕获Chrome内部页面。


我的理解是,这意味着您需要从browserAction中为您的扩展驱动它,像这样:

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

这对我很有用。


I've got some js code in a chrome background extension of 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 ran, the "handleCapture" variable "stream" that is passed in is always undefined? Is this to be expected or is there something that I am missing here?

Also, I've confirmed that my manifest.json contains the capture permission and I am using chrome canary Version 31.0.1607.1 canary Aura.

Thanks, Mike

解决方案

I had this same issue when I was trying to drive a tabCapture purely from a background script, I found this on the tabCapture reference page:

Captures the visible area of the currently active tab. This method can only be used on the currently active page after the extension has been invoked, similar to the way that activeTab works. Note that Chrome internal pages cannot be captured.

My understanding is that this means you need to drive it from a browserAction for your extension, like so:

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

That's what worked for me.

这篇关于chrome.tabCapture.capture返回的流未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆