vondip vondip - 6 months ago 17
Javascript Question

take screen shot using only js in firefox extension

I am thinking of building a firefox extension.
This extension requires the ability of performing screen shots.
Is it possible doing so only using javascript?

Answer

UPDATE: This feature has been removed from Firefox, unless you're writing a plugin. Please look for different alternatives, see http://badassjs.com/post/12473322192/hack-of-the-day-rendering-html-to-a-canvas and https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawWindow

Back in the days, you could: take a screenshot of firefox's window, yes, and it was so easy it hurt. You had to render it into a canvas. See https://developer.mozilla.org/en/drawing_graphics_with_canvas#Rendering_Web_Content_Into_A_Canvas

<canvas id='my-canvas'></canvas>
<script> 
var canvas = document.getElementById('my-canvas');
var ctx = canvas.getContext("2d");
// Draw the window at the top left of canvas, width=100, height=200, white background
// drawWindow has been removed :(
ctx.drawWindow(window, 0,0, 100, 200, "rgb(255,255,255)");
// Open another window with the thumbnail as an image
open(canvas.toDataURL("image/png"));
</script>

If you mean a screenshot of the entire desktop, I don't think so