【问题标题】:Is it possible to capture a screenshot of the client's desktop from within a web application?是否可以从 Web 应用程序中捕获客户端桌面的屏幕截图?
【发布时间】:2018-03-30 06:33:33
【问题描述】:

我想知道是否可以从基于 JavaScript 的 Web 应用程序中捕获客户端桌面的屏幕截图。我想在应用程序中为用户提供一个按钮,他们可以使用它来截取他们的桌面屏幕(不是页面或页面中的元素,实际的操作系统桌面屏幕)。

主要浏览器(Chrome 和 Firefox)是否允许这种操作?我知道可能存在安全问题,但我可以请求用户允许进行这种访问吗?是否有任何库、工具或文档可以帮助我解决这个问题?或者这只是不可行?

我对该主题进行了一些研究,但只找到了在浏览器中截取内容的方法。

【问题讨论】:

标签: javascript google-chrome firefox browser web-applications


【解决方案1】:

看起来这个可以帮助你:How to capture screenshot of parts of the client "desktop" using HTML/JavaScript ?

使用 WebRTC 和 Screen Capturing,您可以截取桌面截图(Firefox 和 Chrome 都支持)。 Javascript 库 RTCMultiConnection 对于使用 WebRTC 非常有用,但也可以不使用额外的库。

【讨论】:

    【解决方案2】:

    是的,它允许这样做。我不知道这是否是一个好的开始,但您可以检查一个可以完成这项工作的开源应用程序。

    这里是 chromium 远程控制应用源码。您可以找到捕获屏幕的代码片段。如果您完成工作,我想听听您的意见。

    Chromium 远程控制应用link

    【讨论】:

      【解决方案3】:

      您只能使用 Canvas 将图像或视频帧捕获为屏幕截图。但是,如果您想捕获网页上的特定元素,请尝试使用此库:html2canvas

      代码如下:

      注意:在drawImage()函数中仔细调整尺寸

      $(".drag").draggable();
      $(".drag").droppable();
      var takeScreenShot = function() {
          html2canvas(document.getElementById("container"), {
              onrendered: function (canvas) {
                  var tempcanvas=document.createElement('canvas');
                  tempcanvas.width=350;
                  tempcanvas.height=350;
                  var context=tempcanvas.getContext('2d');
                  context.drawImage(canvas,112,0,288,200,0,0,350,350);
                  var link=document.createElement("a");
                  link.href=tempcanvas.toDataURL('image/jpg');   //function blocks CORS
                  link.download = 'screenshot.jpg';
                  link.click();
              }
          });
      }
      #container{
          width:400px;
          height:200px;
      }
      #rightcontainer{
          width:300px;
          height:200px;
          background:gray;
          color:#fff;
          margin-left:110px;
          padding:10px;
      }
      #leftmenu{
          color:#fff;
          background-color:green;
          width:100px;
          height:200px;
          position:fixed;
          left:0;
          padding:10px;
      }
      
      button{
          display:block;
          height:20px;
          margin-top:10px;
          margin-bottom:10px;
      }
      .drag{
        width:40px;
        height:20px;
        background-color:blue;
        z-index:100000;
        margin-top:10px;
      }
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
        
        
      <button onclick="takeScreenShot()">Snapshot</button>
      <div id="container">
          <div id="leftmenu">
            Left Side
            <div class="drag">
            </div>
            <div class="drag">
            </div>
            <div class="drag">
            </div>
            Drag----------->
                  &
            Click Snapshot
          </div>
          <div id="rightcontainer">
              Right Side
          </div>
      </div>

      【讨论】:

      • 谢谢,不过我需要的是捕获用户桌面的屏幕截图,而不是 Web 应用程序中的内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-31
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多