Michael said:
I believe it does, based on the documentation for the ScreenGrab
extension to Firefox, which mentions using the canvas element.
ScreenGrab does something similar to what the OP is asking for,
Doesn't it do exactly that -- "capture the content of the browser window as
image"?
though of course in a Firefox-specific manner,
No, in a Canvas-specific manner. Or are you referring to the
(content/Screengrab.)XUL that triggers it? That would be
_Gecko_-specific instead.
and using a browser extension rather than JavaScript.
ScreenGrab, like any other extension for Gecko-based browsers, is primarily
written in JavaScript. You may want to take the time and unzip(1)
${installDir}/extensions/{02450954-cdd9-410f-b1da-db804e18c671}/chrome/screengrab.jar
(of ScreenGrab version 0.96.1), where, in content/Browser.js:100, I have
noticed not only
getCanvas: function() {
return document.createElementNS("
http://www.w3.org/1999/xhtml",
"html:canvas");
// return document.getElementById("screengrab_buffer_canvas");
},
but also, much to my disappointment, a number of unnecessary eval() calls,
like in content/Grab.js:15 --
screengrab.Grab2 = function(targetName, captureName, action) {
try {
// bring focus to us
screengrab.Browser.contentFrame().focus();
var target = eval("new sg." + targetName + "()");
var capture = eval("sg." + captureName);
target.obtainDimensions(function(browser, dimensions) {
capture(browser, dimensions, function(canvas) {
action(canvas);
});
});
} catch (error) {
screengrab.error(error);
}
}
(sic!) -- which, of course, could and should be rewritten as
screengrab.Grab2 = function(targetName, captureName, action) {
try {
// bring focus to us
screengrab.Browser.contentFrame().focus();
var target = new sg[targetName]();
var capture = sg[captureName];
target.obtainDimensions(
function(browser, dimensions) {
capture(browser, dimensions,
function(canvas) {
action(canvas);
});
});
} catch (error) {
screengrab.error(error);
}
};
PointedEars