0

I have been searching around a bit, but didn't find any solution to this issue. I'm not sure why but the stream which I'm getting is null.

As you can see in the code bellow, I'm not using browserAction but instead I'm sending a message to the extension and then calling requestCurrentTabCapture

chrome.runtime.onConnect.addListener(function(port) {
  port.onMessage.addListener(function(msg) {

    switch(msg.type){
      case 'SS_TAB_REQUEST':
        alert("SS_TAB_REQUEST");
        requestCurrentTabCapture(port, msg);
        break;
      case 'SS_TAB_CANCEL':
        break;
      default:
    }
  });
});

function requestCurrentTabCapture(port, msg){
  //chrome.tabs.getCurrent(function(tab) {
    //chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.query({active: true}, function(tab) {
        alert(tab);
        chrome.tabCapture.capture(
          {
            video: true, audio: true,
            videoConstraints: {
             mandatory: {
               chromeMediaSource: 'tab',
               minWidth: 16,
               minHeight: 9,
               maxWidth: 1280,
               maxHeight: 720,
               maxFrameRate: 60,  // Note: Frame rate is variable (0 <= x <= 60).
             },
           },
          },
          function(stream) {
            alert(stream); //<-- NULL
            if (!stream) {
             console.error('Error starting tab capture: ' + chrome.runtime.lastError.message || 'UNKNOWN'));
           }
          }
        );      
    });


    chrome.tabCapture.onStatusChanged.addListener(function (info){
            alert("status: "+info.status); //<-- not shown
            alert("tabId: "+info.tabId); //<-- not shown
            alert("fullscreen: "+info.fullscreen); //<-- not shown
    });
}

Permissions are as follows:

"permissions": [
 "desktopCapture",
 "<all_urls>",
 "tabs",
"activeTab",
 "tabCapture"
]
Sagar Pilkhwal
  • 3,998
  • 2
  • 25
  • 77
  • 1
    In the absence of `currentWindow: true` chrome.tabs.query will return the active debugger window if you have it focused. Also, are there any errors in the [background page console](http://stackoverflow.com/questions/38913799/google-chrome-firefox-do-not-see-extension-output-in-console/38920982)? – wOxxOm Feb 27 '17 at 10:34
  • Thanks for the link, i see `Error starting tab capture: Extension has not been invoked for the current page (see activeTab permission). Chrome pages cannot be captured.` error – Sagar Pilkhwal Feb 27 '17 at 10:37
  • Well, the error is self-explanatory, see the [documentation](https://developer.chrome.com/extensions/tabCapture#method-capture). – wOxxOm Feb 27 '17 at 10:38
  • `Capture can only be started on the currently active tab after the extension has been invoked` ? The error is printed when i'm using `console.error()` in the callback. Please check the edited question. – Sagar Pilkhwal Feb 27 '17 at 10:42
  • 2
    `invoked` is explained in the activeTab link there. It means the user should interact with your extension explicitly. – wOxxOm Feb 27 '17 at 10:44
  • hi, I added the logic for `pageAction`, I'm receiving a valid `stream` object. but when I send `port.postMessage(msg)` and the msg contains `msg.stream = stream` I'm not receiving the stream in my webpage js file. `msg.streamId` is coming like `[Object]` and no data in it – Sagar Pilkhwal Feb 27 '17 at 15:22
  • That's because messaging stringifies objects with JSON.stringify so only simple objects may be passed. You'll need to process the stream where you get it. – wOxxOm Feb 27 '17 at 15:23

0 Answers0