Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 623
Deepak Kushwaha Avatar asked Jun 11 '14 11:06

Deepak Kushwaha


People also ask

How do I enable screen capture in Chrome?

To enable the Screenshot feature in Chrome, go to chrome://flags and search for Screenshots. In the dropdown for “Desktop Screenshots”, select Enabled. You'll see a prompt to restart the browser, click on that.

Does Chrome have a screen capture tool?

Android Intelligence Advice Here's a little-known secret: Chrome actually has a supremely useful built-in command for capturing screenshots — no extensions required. It's flexible, effective, and easy as can be to use.


1 Answers

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.

like image 177
artfulhacker Avatar answered Sep 23 '22 09:09

artfulhacker