Skip to content

Instantly share code, notes, and snippets.

@mfyz
Last active August 29, 2015 13:57
Show Gist options
  • Save mfyz/9862163 to your computer and use it in GitHub Desktop.
Save mfyz/9862163 to your computer and use it in GitHub Desktop.
Take snapshot of a webpage with phantomjs
// run this with phantomjs
//create new webpage object
//var page = new WebPage();
var page = require('webpage').create();
//load the page
page.open('http://mfyz.com', function (status) {
//fire callback to take screenshot after load complete
page.render('mfyz.png');
//finish
phantom.exit();
});
// run this script with node using phantom module
var page = require('webpage').create();
page.open('http://moonit.com', function() {
var pageHeight = page.evaluate(function() {
return document.body.offsetHeight;
});
page.viewportSize = { width: 1200, height: pageHeight + 50 };
page.clipRect = { width: 1200, height: pageHeight + 50 };
// Take screenshot of the page.
page.paperSize = 'Letter';
window.setTimeout(function () {
page.render('screenshot.png');
phantom.exit();
}, 200);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment