Skip to content

Commit 0301236

Browse files
committed
Avoid hanging when a web page constantly requests new resources
1 parent 80115f1 commit 0301236

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Engine/Convert/Resources/PhantomJs-rasterize.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ var page = require('webpage').create(),
3131
system = require('system'),
3232
address, output, size;
3333

34+
// Reference: https://stackoverflow.com/questions/16854788/phantomjs-webpage-timeout
35+
// Add resource timeout to avoid a permanent hang.
36+
page.settings.resourceTimeout = 10000; // ms
37+
page.onResourceTimeout = function(e) {
38+
console.log(e.errorCode); // it'll probably be 408
39+
console.log(e.errorString); // it'll probably be 'Network timeout on resource'
40+
console.log(e.url); // the url whose request timed out
41+
phantom.exit(1);
42+
};
43+
3444
if (system.args.length < 3 || system.args.length > 5) {
3545
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
3646
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');

0 commit comments

Comments
 (0)