Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture chrome tab without browse action

I have a simple method which captures current tab, and it works only when this method triggered by click on extension button (i.e. browserAction).

But when I use this method in setTimeout event it fails with following error:

Unchecked runtime.lastError while running tabCapture.capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.

My simple capture method is:

function captureTab() {
    var constraints = ...
    chrome.tabCapture.capture(constraints, function (stream) {
        if (!stream) {
            console.error("couldn't record tab");
            return;
        }
        // recording succeeded
    });
} 

And it works when it triggered as follows:

chrome.browserAction.onClicked.addListener(function () {
    chrome.tabs.getSelected(null, function (tab) {
        captureTab();
    });
});

But doesn't work when it triggered as follows:

setTimeout(function () {
    chrome.tabs.getSelected(1, function (tab) {
        captureTab();            
    });
}, 1 * 30 * 1000);

Important note: My extension isn't a public extension and it runs only on my browser so I can add any command line switch on start (in order to disable this limitation), if needed.

like image 586
uriel Avatar asked Oct 21 '25 06:10

uriel


1 Answers

Please be aware chrome.tabCapture.capture can only be started on the currently active tab after the extension has been invoked.

Captures the visible area of the currently active tab. Capture can only be started on the currently active tab after the extension has been invoked.

And when you declare activeTab permissions, only the following user gestures enable it

  • Executing a browser action
  • Executing a page action
  • Executing a context menu item
  • Executing a keyboard shortcut from the commands API
  • Accepting a suggestion from the omnibox API

So when you are using setTimeOut, you can not ensure current tab is active.

like image 191
Haibara Ai Avatar answered Oct 23 '25 21:10

Haibara Ai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!