如何使用HTML/JavaScript捕获客户端“桌面”的部分截图?

3

我知道如何捕获网页,但我想知道如何捕获桌面或另一个桌面应用程序?如果有任何方法可以突出显示屏幕的某些部分。就像html2canvas对于网页所做的那样,我们是否可以使用HTML/JS中的浏览器应用程序来处理桌面应用程序?

1个回答

6

是的,这是可能的!
但据我所知,只针对Firefox和Chrome(我使用的是Chrome)。感谢屏幕捕获和WebRTC。有关WebRTC的更多信息

我使用了一个名为RTCMultiConnection的库,非常易于使用,但您也应该能够在不使用任何库的情况下完成。

这里,只是为了给您一个起点:

// 1. Create the connection Objekt
var connection = new RTCMultiConnection();

// 2. Activate screen, which is the whole monitor, not only the browser window!
connection.session = {
    screen: true,
    data: false,
    oneway: true
};

// 3. Create the callback for the stream
connection.onstream = function(event) {
  // Make something with the event
  // event.stream contains the stream, event.mediaElement the media
  // I used event.mediaElement as parameter to draw the frage into an canvas; via context2d.drawImage(event.mediaElement, ...)
  // Then I create an base64 String via canvas.toDataURL("image/png") and 
  // Don't forget to stop the stream if you just want to have one single image
};

// 4. Start Desktop Sharing
connection.open({
  // you could register a onMediaCaptured callback here
});

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接