NetworkAgent tracks all resources loaded by the remote debugger. Use
wasURLRequested(url)
to query whether a resource was loaded.
Return the URL without the query string
function _urlWithoutQueryString(url) {
var index = url.search(/[#\?]/);
if (index >= 0) {
url = url.substr(0, index);
}
return url;
}
Enable the inspector Network domain
function enable() {
return Inspector.Network.enable();
}
Initialize the agent
function load() {
Inspector.Page.on("frameNavigated.NetworkAgent", _onFrameNavigated);
Inspector.Network.on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
}
Unload the agent
function unload() {
_reset();
Inspector.Page.off(".NetworkAgent");
Inspector.Network.off(".NetworkAgent");
}
// Export public functions
exports.wasURLRequested = wasURLRequested;
exports.enable = enable;
exports.load = load;
exports.unload = unload;
});
Return the resource information for a given URL
function wasURLRequested(url) {
return _urlRequested && _urlRequested[url];
}
function _logURL(url) {
_urlRequested[_urlWithoutQueryString(url)] = true;
}
// WebInspector Event: Network.requestWillBeSent
function _onRequestWillBeSent(event, res) {
// res = {requestId, frameId, loaderId, documentURL, request, timestamp, initiator, stackTrace, redirectResponse}
_logURL(res.request.url);
}
function _reset() {
_urlRequested = {};
}
// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(event, res) {
// res = {frame}
// Clear log when navigating to a new page, but not if an iframe was loaded
if (!res.frame.parentId) {
_reset();
}
_logURL(res.frame.url);
}