You may want to modify the XMLHttpRequest.prototype.open
to decorate it with your "tracking" code. Something like this:
var ajaxCalls = [];
XMLHttpRequest.prototype._originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
ajaxCalls.push(url);
this._originalOpen(method, url, async, user, password);
}
The ajaxCalls
array will get populated with the URLs of your Ajax requests. The last request will be at ajaxCalls[ajaxCalls.length - 1]
.
Note that if you want to track only GET
requests, you can simply log URLs only if method === 'GET'
in the open()
method.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…