Update phantomJS

This commit is contained in:
Knah Tsaeb 2017-12-07 15:36:09 +01:00
parent 8a83ef15e9
commit 415c1e4407
3 changed files with 24 additions and 35 deletions

Binary file not shown.

Binary file not shown.

View file

@ -1,39 +1,28 @@
function renderPage(url, output) {
"use strict";
var page = require('webpage').create(),
system = require('system'),
address, output;
var page = require('webpage').create();
var redirectURL = null;
if (phantom.args.length < 2) {
//console.log('Usage: rasterize.js URL filename');
phantom.exit();
if (system.args.length < 2) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px');
console.log(' "800px*600px" window, clipped to 800x600');
phantom.exit(1);
} else {
page.settings.userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:39.0) Gecko/20100101 Firefox/50.0';
address = system.args[1];
output = system.args[2];
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') {
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
phantom.exit(1);
} else {
window.setTimeout(function () {
page.render(output);
page.close();
phantom.exit();
}, 1000);
} else {
console.log('Unable to load the address!');
page.close();
phantom.exit();
}, 200);
}
});
}
}
url = phantom.args[0];
output = phantom.args[1];
renderPage(url, output);