调用代码chrome扩展中的活动选项卡以进行选项卡捕获

时间:2017-05-04 09:00:37

标签: google-chrome google-chrome-extension

我想通过postmessage用chrome进行标签捕获。

以下是我创建的代码。 该消息将由内容脚本发送。

收到邮件后,它会尝试捕获当前标签。



chrome.runtime.onConnect.addListener(function(port){
    port.onMessage.addListener(function(message,sender){
        chrome.tabs.query({"active": true, "currentWindow": true}, function(tab) {
            chrome.tabCapture.capture(captureOptions, 
                function(stream) {
                    mediaRecorder = new MediaRecorder(stream, options);
                    if (stream && message.status == 'started') {

                        var options = {mimeType: "video/webm"};
                        
                        mediaRecorder.start();
                        mediaRecorder.ondataavailable = function(event) {
                            if (event.data.size > 0) {
                                recordedChunks.push(event.data);

                                var blob = new Blob(recordedChunks, {
                                    type: 'video/mp4'
                                });

                                var url = URL.createObjectURL(blob);
                                var a = document.createElement('a');
                                document.body.appendChild(a);
                                a.style = 'display: none';
                                a.href = url;
                                a.download = 'test.webm';
                                a.click();
                                window.URL.revokeObjectURL(url);
                                stream.getVideoTracks()[0].stop();
                            }
                        }
                        
                    }else if(message.status = "stopped"){
                        mediaRecorder.stop();
                    }
                }
            );
        });
    });
});




使用上面的代码我得到了错误



Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.
    at Object.callback (chrome-extension://haogilhkbanjpnkjbdgnefdgllfhldci/background.js:32:31)




有没有办法绕过这个?

0 个答案:

没有答案