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

How to capture screenshot of parts of the client "desktop" using HTML/JavaScript ?

本文关键字:桌面 使用 JavaScript HTML 客户端部 何捕获 屏幕截图      更新时间:2023-09-26

我知道如何捕获网页,但我在问如何捕获桌面或桌面中的另一个应用程序?如果有任何突出显示屏幕的部分。就像html2canvas为网页所做的那样,我们可以使用HTML/JS中的浏览器应用程序为桌面应用程序做些什么吗?

是的,这是可能的
但据我所知,仅适用于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
});
相关文章: