Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
390 views
in Technique[技术] by (71.8m points)

javascript - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...