Modules (188)

NetworkAgent

Description

NetworkAgent tracks all resources loaded by the remote debugger. Use wasURLRequested(url) to query whether a resource was loaded.

Dependencies

Functions

Private

_urlWithoutQueryString

Return the URL without the query string

URL string
    function _urlWithoutQueryString(url) {
        var index = url.search(/[#\?]/);
        if (index >= 0) {
            url = url.substr(0, index);
        }
        return url;
    }
Public API

enable

Enable the inspector Network domain

Returns: jQuery.Promise
A promise resolved when the Network.enable() command is successful.
    function enable() {
        return Inspector.Network.enable();
    }
Public API

load

Initialize the agent

    function load() {
        Inspector.Page.on("frameNavigated.NetworkAgent", _onFrameNavigated);
        Inspector.Network.on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
    }
Public API

unload

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;
});
Public API

wasURLRequested

Return the resource information for a given URL

url string
    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);
    }