Take Screenshot of Browser via JavaScript (or something else)

前端 未结 15 1936
天命终不由人
天命终不由人 2020-12-15 04:43

For support reasons I want to be able for a user to take a screenshot of the current browser window as easy as possible and send it over to the server.

Any (crazy)

相关标签:
15条回答
  • 2020-12-15 05:21

    This may not work for you, but on IE you can use the snapsie plugin. It doesn't seem to be in development anymore, but the last release is available from the linked site.

    0 讨论(0)
  • 2020-12-15 05:24

    I've seen people either do this with two approaches:

    1. setup a separate server for screenshotting and run a bunch of firefox instances on there, check out these two gem if you're doing it in ruby: selenium-webdriver and headless

    2. use a hosted solution like http://url2png.com (way easier)

    0 讨论(0)
  • 2020-12-15 05:25

    That would appear to be a pretty big security hole in JavaScript if you could do this. Imagine a malicious user installing that code on your site with a XSS attack and then screenshotting all of your daily work. Imagine that happening with your online banking...

    However, it is possible to do this sort of thing outside of JavaScript. I developed a Swing application that used screen capture code like this which did a great job of sending an email to the helpdesk with an attached screenshot whenever the user encountered a RuntimeException.

    I suppose you could experiment with a signed Java applet (shock! horror! noooooo!) that hung around in the corner. If executed with the appropriate security privileges given at installation it might be coerced into executing that kind of screenshot code.

    For convenience, here is the code from the site I linked to:

    import java.awt.Dimension;
    import java.awt.Rectangle;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.image.BufferedImage;
    import javax.imageio.ImageIO;
    import java.io.File;
    
    ...
    
    public void captureScreen(String fileName) throws Exception {
    
       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
       Rectangle screenRectangle = new Rectangle(screenSize);
       Robot robot = new Robot();
       BufferedImage image = robot.createScreenCapture(screenRectangle);
       ImageIO.write(image, "png", new File(fileName));
    }
    ...
    
    0 讨论(0)
  • 2020-12-15 05:27

    Please see the answer shared here for a relatively successful implementation of this: https://stackoverflow.com/a/6678156/291640

    Utilizing: https://github.com/niklasvh/html2canvas

    0 讨论(0)
  • 2020-12-15 05:29

    Print Screen? Old school and a couple of keypresses, but it works!

    0 讨论(0)
  • 2020-12-15 05:31

    You could try to render the whole page in canvas and save this image back to server. have fun :)

    0 讨论(0)
提交回复
热议问题