Skip to content

Instantly share code, notes, and snippets.

@ZER0
Created April 15, 2014 06:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZER0/10708822 to your computer and use it in GitHub Desktop.
Save ZER0/10708822 to your computer and use it in GitHub Desktop.
Add-on SDK: take a screenshot of the active tab's content
const { window: { document } } = require('sdk/addon/window');
const { getTabContentWindow, getActiveTab } = require('sdk/tabs/utils');
const { getMostRecentBrowserWindow } = require('sdk/window/utils');
const canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
document.documentElement.appendChild(canvas);
function captureActiveTab() {
let contentWindow = getTabContentWindow(getActiveTab(getMostRecentBrowserWindow()));
let w = contentWindow.innerWidth;
let h = contentWindow.innerHeight;
let x = contentWindow.scrollX;
let y = contentWindow.scrollY;
canvas.width = w;
canvas.height = h;
let ctx = canvas.getContext('2d');
ctx.drawWindow(contentWindow, x, y, w, h, '#000');
return canvas.toDataURL();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment