PhantomJS - onResourceTimeout()



This callback is called when the requested resource timesout. That is when the settings.resourceTimeout callback is used.

It contains one argument i.e. request that have the following details −

  • Id − The number of the requested resource

  • Method − The http method

  • URL − The URL of the requested resource

  • Time − Date object containing the date of the request

  • Headers − List of the http headers

  • ErrorCode − The error code of the error

  • ErrorString − The text message of the error

Syntax

Its syntax is as follows −

page.onResourceTimeout = function(request) {}

Example

var wpage = require('webpage').create(); 
wpage.onResourceTimeout = function(request) { 
   console.log("Data from request:"); 
   console.log(JSON.stringify(request)); 
} 
wpage.settings.resourceTimeout = '3'; 
wpage.open('http://localhost/tasks/request.html', function(status) { 
}); 

The above program generates the following output.

Data from request: 
{"errorCode":408,"errorString":"Network timeout onresource.",
"headers":[{"name":"Accept","value":"text/html,application/xhtml+xml ,
application/xml;q=0.9,*/*;q=0.8"},{"name":"User-Agent","value":"Mozilla/5.0 
(Windows NT 6.2; WOW64) AppleWebKit/538.1 (KHTML, like Gecko) 
PhantomJS/2.1.1 Safari/538.1"}],"id":1,
"method":"GET","time":"2017-0507T13:32:12.545Z",
"url":"http://localhost/tasks/request.html" 
}
phantomjs_webpage_module_events_callbacks.htm
Advertisements