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