mirror of https://github.com/vitalif/phantomjs
Improve rasterize.js
- Add onResourceTimeout to prevent process hang forever - Output address unreachable and set exit code to 1 - Increase setTimeout from 200ms to 500ms https://github.com/ariya/phantomjs/issues/119111.x
parent
80e08eb784
commit
5b426f22fb
|
@ -2,6 +2,12 @@ var page = require('webpage').create(),
|
||||||
system = require('system'),
|
system = require('system'),
|
||||||
address, output, size;
|
address, output, size;
|
||||||
|
|
||||||
|
page.settings.resourceTimeout = 600000; // 10 minutes
|
||||||
|
page.onResourceTimeout = function (e) {
|
||||||
|
console.log('\n' + e.errorCode + ': ' + e.errorString + ' ' + e.url);
|
||||||
|
phantom.exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
if (system.args.length < 3 || system.args.length > 5) {
|
if (system.args.length < 3 || system.args.length > 5) {
|
||||||
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
|
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(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
||||||
|
@ -36,13 +42,13 @@ if (system.args.length < 3 || system.args.length > 5) {
|
||||||
}
|
}
|
||||||
page.open(address, function (status) {
|
page.open(address, function (status) {
|
||||||
if (status !== 'success') {
|
if (status !== 'success') {
|
||||||
console.log('Unable to load the address!');
|
console.log('Unable to load the address: ' + address);
|
||||||
phantom.exit(1);
|
phantom.exit(1);
|
||||||
} else {
|
} else {
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
page.render(output);
|
page.render(output);
|
||||||
phantom.exit();
|
phantom.exit(0);
|
||||||
}, 200);
|
}, 500);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue