phantomJS webpage timeout

后端 未结 1 1996
猫巷女王i
猫巷女王i 2020-12-23 10:14

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 :

 \"

        
相关标签:
1条回答
  • 2020-12-23 10:39

    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.

    0 讨论(0)
提交回复
热议问题