I'm developing a Firefox add-on using sdk 1.17. It contains a panel with a button inside (Developed using ExtJs), I want to take the screen shot of the current page when user clicks the button. In Google chrome there is an API (chrome.page-capture) is there. But I could not find the similar one in Firefox. In firefox how to do this task from the main.js.
5
votes
1 Answers
5
votes
O.k I have found the answer. This code can be used to take the full page screen shot.
In your main.js add this code.
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
var tab = require('sdk/tabs/utils').getActiveTab(window);
var myData;
tabs.activeTab.attach({
contentScript: "self.postMessage(document.body.scrollHeight);",//recieves the total scroll height of tab
onMessage: function(data)
{
console.log("Tab data received: " + data);
myData = data;
var thumbnail = window.document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
window = tab.linkedBrowser.contentWindow;
thumbnail.width = window.screen.availWidth ;
thumbnail.height = window.screen.availHeight ;
var ctx = thumbnail.getContext("2d");
var snippetWidth = window.outerWidth ;
var snippetHeight = window.outerHeight ;
ctx.canvas.left = 0;
ctx.canvas.top = 0;
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = myData;//canvas height is made equal to the scroll height of window
ctx.drawWindow(window, 0, 0, snippetWidth, snippetHeight+myData, "rgb(255,255,255)");//
var imageDataUri=thumbnail.toDataURL('image/png');
imageDataUri = imageDataUri.replace("image/png", "image/octet-stream");
tabs.open(imageDataUri);
}
});
This is done with addon sdk 1.17. Works cool.