Take Screenshot of Browser via JavaScript (or something else) Take Screenshot of Browser via JavaScript (or something else) javascript javascript

Take Screenshot of Browser via JavaScript (or something else)


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));}...


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


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