Created
March 4, 2016 23:36
-
-
Save miketaylr/e6dc2ef451539cb89d87 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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