本文介绍了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时,发生了同样的问题,我在参考页面:

我的理解是,这意味着您需要从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:

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返回的流未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-20 20:22