- 檔案系統模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 系統模組
- PhantomJS - 屬性
- Web 伺服器模組
- PhantomJS - 屬性
- PhantomJS - 方法
- 其他內容
- 命令列介面
- PhantomJS - 螢幕截圖
- PhantomJS - 頁面自動化
- PhantomJS - 網路監控
- PhantomJS - 測試
- PhantomJS - REPL
- PhantomJS - 示例
- PhantomJS 有用的資源
- PhantomJS - 快速指南
- PhantomJS - 有用的資源
- PhantomJS - 討論
PhantomJS - onResourceTimeout()
在請求的資源超時時將呼叫此回撥。即 settings.resourceTimeout 回撥正在使用時。
它包含一個引數,即 request,其中包含以下詳細資訊 -
Id - 請求的資源數
Method - http 方法
URL - 請求的資源的 URL
Time - 包含請求日期的 Date 物件
Headers - http 頭的列表
ErrorCode - 錯誤的錯誤程式碼
ErrorString - 錯誤的文字訊息
語法
它的語法如下 -
page.onResourceTimeout = function(request) {}
示例
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('https:///tasks/request.html', function(status) {
});
上述程式生成以下輸出。
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":"https:///tasks/request.html"
}
phantomjs_webpage_module_events_callbacks.htm
廣告