我有一个使用 AngularJS 构建的 Web 应用程序。我正在使用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);
});