Is there a way to bypass Chrome desktopCapture's Choose Media Screen?

1.6k views Asked by At

I am using Chrome desktopCapture API to create a screen recording Chrome App.

Currently, I am doing this:


app.js:

    document.querySelector('#startRecording').addEventListener('click', recordClick);
    
    function recordClick(event) {
        console.log("Start Button clicked");
        pending_request_id = chrome.desktopCapture.chooseDesktopMedia(["screen"], accessToRecord);
    }

function accessToRecord(id, options){
    if (!id) {
        console.log('Access rejected.');
        return;
    }

    let audioConstraint = {
        mandatory: {
          chromeMediaSource: 'desktop',
          chromeMediaSourceId: id
        }
    };
  
    console.log(options.canRequestAudioTrack);

    if (!options.canRequestAudioTrack)
      audioConstraint = false;
    //console.log("id is: "+id);

    navigator.webkitGetUserMedia({
        audio : audioConstraint,
        video : {
            mandatory: {
                chromeMediaSource: 'desktop',
                chromeMediaSourceId: id,
                maxWidth:screen.width,
                maxHeight:screen.height
            }
        }
    }, startStream, failedStream);
}

background.js:

chrome.app.runtime.onLaunched.addListener(function() {
  console.log("Launch Link Clicked");
  chrome.app.window.create('index.html', {
    bounds: {
      width: 800,
      height: 600
    }
  });
});

manifest.json:

{
    "manifest_version" : 2,
    "name" : "My Screen Recorder",
    "description" : "Allows screen recording",
    "version" : "1",
   "app" : {
    "background" : {
        "scripts" : ["background.js"]
    }
   },    
   "permissions" : ["desktopCapture"]
}

Behavior this creates on UI:

  1. I click on my Chrome App and it shows me a "Start Recording" button(id=startRecording used in above code). Start Recording button - custom screen
  2. Once I clock on this button it shows me this Google screen to select what I want to record: Google's Choose media prompt
  3. Then I start using this screen.

What I want to achieve: A way to bypass this Google generated screen to choose the Media to be recorded. I want to pass the media type in my code and on clicking the first "Start Recording" button, I want it to start recording the type I passed in code and not show me the Choose media prompt.

Is it possible to do that?

1

There are 1 answers

1
lights0123 On

No, for security reasons—Chrome doesn't want any tool to be able to access sensitive data from outside the browser. You may, however, capture the current tab without prompting with chrome.tabs.captureVisibleTab.