Deepak Kushwaha
Deepak Kushwaha

Reputation: 71

Desktop capture chrome plugin

I was developing a chrome plugin in which captures desktop screen. I am using the sample plugin example given here... https://developer.chrome.com/extensions/samples#desktop-capture-example But in this example as we click the start button a dialog pop ups which asks the user which screen or window to share but I want to share my current screen what changes do I make in this code

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

function gotStream(stream) {
  console.log("Received local stream");
  var video = document.querySelector("video");
  video.src = URL.createObjectURL(stream);
  localstream = stream;
  stream.onended = function() { console.log("Ended"); };
}

function getUserMediaError() {
  console.log("getUserMedia() failed.");
}

function onAccessApproved(id) {
if (!id) {
  console.log("Access rejected.");
   return;
}
navigator.webkitGetUserMedia({
audio:false,
video: { mandatory: { chromeMediaSource: "desktop",
                        chromeMediaSourceId: id } }
  }, gotStream, getUserMediaError);
 }

 var pending_request_id = null;

 document.querySelector('#start').addEventListener('click', function(e) {
 pending_request_id = chrome.desktopCapture.chooseDesktopMedia(
 ["screen"], onAccessApproved); 
 });

document.querySelector('#cancel').addEventListener('click', function(e) {
 if (pending_request_id != null) {
 chrome.desktopCapture.cancelChooseDesktopMedia(pending_request_id);
}
});

what should be the value of the chromeMediaSourceId so that the default selection is the current screen;

basically i want to avoid this screen .. enter image description here

Plz help... Regards

Upvotes: 6

Views: 7164

Answers (1)

artfulhacker
artfulhacker

Reputation: 4873

You can't do this. The manifest permission allows you to provide this feature but the user still has to select the screen and hit share.

Like others said, this is a security feature to prevent your extension from triggering this without informing the user.

Upvotes: 2

Related Questions