I have set up a script to create webshots of our app. It runs perfectly and all is fine Until I encounter an image with a broken url :
\"
PhantomJS 1.9 has introduced a new setting, resourceTimeout
, that controls how long a request can take before it gets cancelled. Along with that, there's a onResourceTimeout
event that is triggered if/when a request times out.
Here's a code snippet illustrating all of the above:
var page = require('webpage').create();
page.settings.resourceTimeout = 5000; // 5 seconds
page.onResourceTimeout = function(e) {
console.log(e.errorCode); // it'll probably be 408
console.log(e.errorString); // it'll probably be 'Network timeout on resource'
console.log(e.url); // the url whose request timed out
phantom.exit(1);
};
page.open('http://...', function (status) {
...
}
Unfortunately those options are poorly documented right now. I had to go through GitHub discussions and the PhantomJS source code in order to find them out.