Soshot/bin/rasterize.js
2016-12-12 15:27:29 +01:00

39 lines
1.1 KiB
JavaScript

function renderPage(url, output) {
var page = require('webpage').create();
var redirectURL = null;
if (phantom.args.length < 2) {
//console.log('Usage: rasterize.js URL filename');
phantom.exit();
} else {
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/50.0';
page.viewportSize = { width: 1280, height:1024};
page.onResourceReceived = function(resource) {
if (url == resource.url && resource.redirectURL) {
redirectURL = resource.redirectURL;
}
};
page.open(url, function (status) {
if (redirectURL) {
renderPage(redirectURL);
} else if (status == 'success') {
window.setTimeout(function () {
page.render(output);
page.close();
phantom.exit();
}, 1000);
} else {
console.log('Unable to load the address!');
page.close();
phantom.exit();
}
});
}
}
url = phantom.args[0];
output = phantom.args[1];
renderPage(url, output);