Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using HTML5/Canvas/JavaScript to take in-browser screenshots

Google's "Report a Bug" or "Feedback Tool" lets you select an area of your browser window to create a screenshot that is submitted with your feedback about a bug.

Google Feedback Tool ScreenshotScreenshot by Jason Small, posted in a duplicate question.

How are they doing this? Google's JavaScript feedback API is loaded from here and their overview of the feedback module will demonstrate the screenshot capability.

like image 846
joelvh Avatar asked Feb 06 '11 06:02

joelvh


People also ask

How do I take a screenshot of an entire browser?

Also, you can press Ctrl+Shift+P on Windows or Command+Shift+P on Mac. Type screenshot into the search box. Select Capture full-size screenshot. Once Chrome takes the screenshot, it should save it into your Downloads folder.

How do you take a screenshot in HTML?

HTML Elements Screenshot enables you to capture a full or partial screenshot from any webpage. It uses an open-source JavaScript library called - html2canvas. To work with this add-on, simply click on the toolbar icon to activate the add-on. Then, select any desired element with mouse left-click.


2 Answers

Your web app can now take a 'native' screenshot of the client's entire desktop using getUserMedia():

Have a look at this example:

https://www.webrtc-experiment.com/Pluginfree-Screen-Sharing/

The client will have to be using chrome (for now) and will need to enable screen capture support under chrome://flags.

like image 20
Matt Sinclair Avatar answered Oct 12 '22 01:10

Matt Sinclair


JavaScript can read the DOM and render a fairly accurate representation of that using canvas. I have been working on a script which converts HTML into a canvas image. Decided today to make an implementation of it into sending feedbacks like you described.

The script allows you to create feedback forms which include a screenshot, created on the client's browser, along with the form. The screenshot is based on the DOM and as such may not be 100% accurate to the real representation as it does not make an actual screenshot, but builds the screenshot based on the information available on the page.

It does not require any rendering from the server, as the whole image is created on the client's browser. The HTML2Canvas script itself is still in a very experimental state, as it does not parse nearly as much of the CSS3 attributes I would want it to, nor does it have any support to load CORS images even if a proxy was available.

Still quite limited browser compatibility (not because more couldn't be supported, just haven't had time to make it more cross browser supported).

For more information, have a look at the examples here:

http://hertzen.com/experiments/jsfeedback/

edit The html2canvas script is now available separately here and some examples here.

edit 2 Another confirmation that Google uses a very similar method (in fact, based on the documentation, the only major difference is their async method of traversing/drawing) can be found in this presentation by Elliott Sprehn from the Google Feedback team: http://www.elliottsprehn.com/preso/fluentconf/

like image 170
Niklas Avatar answered Oct 12 '22 02:10

Niklas