Firefox addon sdk 1.17 take screenshot

I am developing a Firefox add-in using sdk 1.17. It contains a panel with a button inside (designed using ExtJs), I want to take a screenshot from the current page when the user clicks the button. Google Chrome has an API (chrome.page-capture). But I could not find a similar one in Firefox. In firefox, how to complete this task from main.js.

+5
source share
1 answer

Ok I found the answer. This code can be used to capture the full screen of the page.

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 using addon sdk 1.17. It works cool.

+5
source

Source: https://habr.com/ru/post/1205350/


All Articles