拍摄带有JavaScript的网页的屏幕截图?

时间:2020-03-05 18:52:41  来源:igfitidea点击:

是否可以使用JavaScript截取网页的屏幕截图,然后将其提交回服务器?

我不太担心浏览器的安全性问题。等,因为实施将针对HTA。但是有可能吗?

解决方案

回答

我们可以使用HTA和VBScript来实现。只需调用外部工具即可进行屏幕截图。我忘记了名称,但是在WindowsVista上有一个用于截屏的工具。我们甚至不需要额外安装。

至于自动,则完全取决于我们使用的工具。如果它具有API,我相信我们可以通过几次Visual Basic调用来触发屏幕截图和保存过程,而用户不会知道我们做了什么。

既然我们提到了HTA,我假设我们使用的是Windows,并且(可能)非常了解环境(例如OS和版本)。

回答

对于报告错误,我们也有类似的要求。由于它是针对Intranet方案的,因此我们能够使用浏览器插件(例如Firefox的Fireshot和InternetExplorer的IE截图)。

回答

我已经通过使用ActiveX控件为HTA完成了此操作。在VB6中构建控件以截取屏幕截图非常容易。我必须使用keybd_event API调用,因为SendKeys无法执行PrintScreen。这是该代码:

Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Public Const CaptWindow = 2

Public Sub ScreenGrab()
   keybd_event &H12, 0, 0, 0
   keybd_event &H2C, CaptWindow, 0, 0
   keybd_event &H2C, CaptWindow, &H2, 0
   keybd_event &H12, 0, &H2, 0
End Sub

这只会使我们到达将窗口移到剪贴板的程度。

另一个选择是,如果要获取屏幕快照的窗口是HTA,则只需使用XMLHTTPRequest将DOM节点发送到服务器,然后在服务器端创建屏幕快照。

回答

对于我们来说,这可能不是理想的解决方案,但仍然值得一提。

Snapsie是一个开放源ActiveX对象,它可以捕获和保存Internet Explorer屏幕快照。一旦在客户端上注册了DLL文件,我们就应该能够捕获屏幕截图,并使用JavaScript将文件上传到服务器。缺点:它需要在客户端注册DLL文件,并且只能与InternetExplorer一起使用。

回答

SnapEngage使用Java小程序(1.5+)制作浏览器屏幕截图。 AFAIK,java.awt.Robot应该执行用户仅允许applet一次执行的工作。

我刚刚找到了一篇关于它的文章:

  • 堆栈溢出问题JavaScript代码无需使用ActiveX即可截取网站的屏幕截图
  • 博客文章SnapABug的工作原理以及应采取的措施

回答

如果有可能这样做的话是Pounder的方法,那就是将整个人体元素设置为canvase,然后使用canvas2image?

http://www.nihilogic.dk/labs/canvas2image/

回答

这样做的一种可能方法是,如果在Windows上运行并安装了.NET,则可以执行以下操作:

public Bitmap GenerateScreenshot(string url)
{
    // This method gets a screenshot of the webpage
    // rendered at its full size (height and width)
    return GenerateScreenshot(url, -1, -1);
}

public Bitmap GenerateScreenshot(string url, int width, int height)
{
    // Load the webpage into a WebBrowser control
    WebBrowser wb = new WebBrowser();
    wb.ScrollBarsEnabled = false;
    wb.ScriptErrorsSuppressed = true;
    wb.Navigate(url);
    while (wb.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); }

    // Set the size of the WebBrowser control
    wb.Width = width;
    wb.Height = height;

    if (width == -1)
    {
        // Take Screenshot of the web pages full width
        wb.Width = wb.Document.Body.ScrollRectangle.Width;
    }

    if (height == -1)
    {
        // Take Screenshot of the web pages full height
        wb.Height = wb.Document.Body.ScrollRectangle.Height;
    }

    // Get a Bitmap representation of the webpage as it's rendered in the WebBrowser control
    Bitmap bitmap = new Bitmap(wb.Width, wb.Height);
    wb.DrawToBitmap(bitmap, new Rectangle(0, 0, wb.Width, wb.Height));
    wb.Dispose();

    return bitmap;
}

然后通过PHP我们可以执行以下操作:

exec(" CreateScreenShot.exe -url http://...。-保存C:/ shots domain_page.png");`

然后,我们将屏幕截图保存在服务器端。