2014-10-28 25 views
4

我有一個使用AngularJS構建的Web應用程序。 我正在使用phantomjs網絡監控嗅探頁面加載時從網站觸發的所有請求。我得到的請求以下列表:從phantomjs網絡監控結果中缺少請求

"https:.../assets/application-bf61473a35661d960c262995b314b0af.css" 
"https:.../assets/lib/modernizr-c569e351684c78953f5f6298b4e1e485.js" 
"https:.../assets/application-04936fc61dbebda777c3f816afa39726.js" 
"https://www.google-analytics.com/analytics.js" 
"https://ssl.google-analytics.com/ga.js" 
"https:.../assets/app_install_page_header-a4b182016c1769bad626d1409b6c95f1.png" 
"https:.../assets/app_install_page_landing_text-14a162dca43a9a84b9fe0a7a77472fad.png" 

的問題是,該名單不包括任何動態請求,例如:

我爲了使用WAITFOR方法給phantomjs時間等待延遲的請求,但它並沒有幫助。

我用這個文檔http://phantomjs.org/network-monitoring.html

代碼:

var page = require('webpage').create(); 

page.onConsoleMessage = function(msg, lineNum, sourceId) { 
    console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")'); 
}; 

page.onError = function(msg, trace) { 
    var msgStack = ['ERROR: ' + msg + trace]; 
    console.error(msgStack.join('\n')); 
}; 

page.onResourceRequested = function(request) { 
    url = request.url 
    console.log(url); 
}; 

page.onRecourseReceived = function(response) { 
    console.log('received: ' + JSON.stringify(response, undefined, 4)); 
}; 

page.onLoadFinished = function() { 
    page.render("on_finish.png"); 
}; 

page.open(address, function(status){ 

    setTimeout(function(){ 
     phantom.exit(); 
    }, 15000); 
}); 
+0

'waitFor'在您等待某些特定事物時非常有用。你在等什麼(請顯示你的代碼)。在你的情況''setTimeout(function(){phantom.exit();},5000);'應該就足夠了。 – 2014-10-28 13:29:10

+0

請註冊['onConsoleMessage'](http://phantomjs.org/api/webpage/handler/on-console-message.html)和['onError'](http://phantomjs.org/api/網頁/處理程序/ on-error.html)事件。也許有錯誤。 – 2014-10-28 13:30:02

+0

我無法捕捉任何錯誤的方法,但我檢查了瀏覽器控制檯,並有一些第三方庫的錯誤,但不是谷歌分析例如。 – 2014-10-28 14:54:44

回答

3

看來你有它本身使用https分析的HTTP站點。
最近POODLE漏洞迫使網站所有者禁用SSLv3。由於PhantomJS < v1.9.8默認情況下使用SSLv3,因爲握手失敗,分析和其他腳本無法加載。因此,隨後的請求無法運行,因爲腳本甚至沒有到達瀏覽器。

由於PhantomJS 1.9.8默認協議設置爲TLSv1,但可以通過將--ssl-protocol=tlsv1作爲命令行選項手動設置爲早期版本。有關更多信息,請參見this answer

這可以通過註冊一個onResourceError事件處理程序來檢查。錯誤消息將包含類似SSL handshake failed

+0

感謝您的回答。 – 2014-10-29 10:06:15