2014-10-28 54 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