Last active
January 11, 2016 02:12
-
-
Save keelii/8ed40ae6b70c364576d8 to your computer and use it in GitHub Desktop.
This file contains 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
var page = require('webpage').create(); | |
var system = require('system'); | |
page.settings.userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"; | |
page.viewportSize = { width: 1280, height: 800}; | |
if (system.args.length === 1) { | |
console.log('Usage: browser_screenshots.js <some URL>'); | |
phantom.exit(1); | |
} else { | |
var url = system.args[1]; | |
console.log('Loading page > ' + url); | |
console.log('...'); | |
page.open(url, function(status) { | |
console.log('Loading ['+ status +'].'); | |
if ( status === "success" ) { | |
var res = page.evaluate(function() { | |
function scrollPage(pageHeight, perHeight, interval) { | |
var perHeight = perHeight || 500; | |
var pageHeight = pageHeight || 10000; | |
var step = pageHeight / perHeight; | |
var i = 0; | |
var len = step; | |
var interval = interval || 200; | |
var t = setInterval(function() { | |
if (i > len) { | |
clearInterval(t); | |
} | |
document.body.scrollTop = perHeight * i; | |
i++; | |
}, interval); | |
return interval * len; | |
} | |
return scrollPage(); | |
}); | |
console.log('Capture page.'); | |
console.log('...'); | |
setTimeout(function() { | |
page.render('result.png'); | |
console.log('Generating image.'); | |
phantom.exit(); | |
}, res + 500); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment