google-chrome – chrome.tabCapture.capture返回的流是未定义的

我在以下的chrome背景扩展中有一些js代码:

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

但是,当运行它时,传入的“handleCapture”变量“stream”总是未定义的?这是预期的还是我在这里缺少的东西?

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

谢谢,
麦克风

最佳答案 当我尝试纯粹从后台脚本驱动tabCapture时,我遇到了同样的问题,我在
tabCapture参考页面上找到了这个:

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.

我的理解是,这意味着您需要从您的扩展的browserAction驱动它,如下所示:

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

这对我有用.

点赞