From 5b426f22fb4fcf79944e5b0fc0726ca22ef639bc Mon Sep 17 00:00:00 2001 From: onlyurei Date: Sat, 17 May 2014 14:13:21 -0500 Subject: [PATCH] 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/11911 --- examples/rasterize.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/rasterize.js b/examples/rasterize.js index b0e0f67d..8c418c3f 100644 --- a/examples/rasterize.js +++ b/examples/rasterize.js @@ -2,6 +2,12 @@ var page = require('webpage').create(), system = require('system'), 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) { console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]'); 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) { if (status !== 'success') { - console.log('Unable to load the address!'); + console.log('Unable to load the address: ' + address); phantom.exit(1); } else { window.setTimeout(function () { page.render(output); - phantom.exit(); - }, 200); + phantom.exit(0); + }, 500); } }); }