Skip to content

Instantly share code, notes, and snippets.

@miketaylr
Created March 4, 2016 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miketaylr/e6dc2ef451539cb89d87 to your computer and use it in GitHub Desktop.
Save miketaylr/e6dc2ef451539cb89d87 to your computer and use it in GitHub Desktop.
getScreenshot: (tab) => {
Task.spawn(function* () {
let win = tab.window;
let dpr = win.devicePixelRatio;
let canvas = win.document.createElement("canvas");
let ctx = canvas.getContext("2d");
// Grab the visible viewport coordinates
let x = win.document.documentElement.scrollLeft;
let y = win.document.documentElement.scrollTop;
let w = win.innerWidth;
let h = win.innerHeight;
// Scale according to devicePixelRatio
canvas.width = dpr * w;
canvas.height = dpr * h;
ctx.scale(dpr, dpr);
ctx.drawWindow(win, x, y, w, h, '#ffffff');
return yield canvas.toDataURL();
// Test on the Nexus 6P, because that has a crazy screen.
});
},
[...]
let data = this.getScreenshot(selectedTab);
Services.console.logStringMessage('~~~~' + data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment