Class Network


  • public class Network
    extends java.lang.Object
    All available DevTools Network methods and events
    • Constructor Detail

      • Network

        public Network()
    • Method Detail

      • clearBrowserCache

        public static Command<java.lang.Void> clearBrowserCache()
      • clearBrowserCookies

        public static Command<java.lang.Void> clearBrowserCookies()
      • continueInterceptedRequest

        @Beta
        public static Command<java.lang.Void> continueInterceptedRequest​(InterceptionId interceptionId,
                                                                         java.util.Optional<ErrorReason> errorReason,
                                                                         java.util.Optional<java.lang.String> rawResponse,
                                                                         java.util.Optional<java.lang.String> url,
                                                                         java.util.Optional<java.lang.String> method,
                                                                         java.util.Optional<java.lang.String> postData,
                                                                         java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>> headers,
                                                                         java.util.Optional<AuthChallengeResponse> authChallengeResponse)
        Response to Network.requestIntercepted which either modifies the request to continue with any modifications, or blocks it, or completes it with the provided response bytes. If a network fetch occurs as a result which encounters a redirect an additional Network.requestIntercepted event will be sent with the same InterceptionId. (EXPERIMENTAL)
        Parameters:
        interceptionId - Identifier for the intercepted request
        errorReason - If set this causes the request to fail with the given reason. Passing Aborted for requests marked with isNavigationRequest also cancels the navigation. Must not be set in response to an authChallenge
        rawResponse - If set the requests completes using with the provided base64 encoded raw response, including HTTP status line and headers etc... Must not be set in response to an authChallenge
        url - If set the request url will be modified in a way that's not observable by page. Must not be set in response to an authChallenge
        method - If set this allows the request method to be overridden. Must not be set in response to an authChallenge
        postData - If set this allows postData to be set. Must not be set in response to an authChallenge
        headers - If set this allows the request headers to be changed. Must not be set in response to an authChallenge
        authChallengeResponse - Response to a requestIntercepted with an authChallenge. Must not be set otherwise
        Returns:
        DevTools Command
      • deleteCookies

        public static Command<java.lang.Void> deleteCookies​(java.lang.String name,
                                                            java.util.Optional<java.lang.String> url,
                                                            java.util.Optional<java.lang.String> domain,
                                                            java.util.Optional<java.lang.String> path)
        Deletes browser cookies with matching name and url or domain/path pair
        Parameters:
        name - Name of the cookies to remove
        url - If specified, deletes all the cookies with the given name where domain and path match provided URL
        domain - If specified, deletes only cookies with the exact domain.
        path - If specified, deletes only cookies with the exact path
        Returns:
        DevTools Command
      • disable

        public static Command<java.lang.Void> disable()
        Disables network tracking, prevents network events from being sent to the client.
        Returns:
        DevTools Command
      • emulateNetworkConditions

        public static Command<java.lang.Void> emulateNetworkConditions​(boolean offline,
                                                                       double latency,
                                                                       double downloadThroughput,
                                                                       double uploadThroughput,
                                                                       java.util.Optional<ConnectionType> connectionType)
        Activates emulation of network conditions.
        Parameters:
        offline - True to emulate internet disconnection.
        latency - Minimum latency from request sent to response headers received (ms).
        downloadThroughput - Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.
        uploadThroughput - Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.
        connectionType - The underlying connection technology that the browser is supposedly using.
        Returns:
        DevTools Command
      • enable

        public static Command<java.lang.Void> enable​(java.util.Optional<java.lang.Integer> maxTotalBufferSize,
                                                     java.util.Optional<java.lang.Integer> maxResourceBufferSize,
                                                     java.util.Optional<java.lang.Integer> maxPostDataSize)
        Enables network tracking, network events will now be delivered to the client.
        Parameters:
        maxTotalBufferSize - Buffer size in bytes to use when preserving network payloads (XHRs, etc).
        maxResourceBufferSize - Per-resource buffer size in bytes to use when preserving network payloads (XHRs, etc).
        maxPostDataSize - Longest post body size (in bytes) that would be included in requestWillBeSent notification
        Returns:
        DevTools Command
      • getAllCookies

        public static Command<Cookies> getAllCookies()
        Returns all browser cookies. Depending on the backend support, will return detailed cookie information in the cookies field
        Returns:
        Array of Cookies with a "asSeleniumCookies" method
      • getCertificate

        @Beta
        public static Command<java.util.List<java.lang.String>> getCertificate​(java.lang.String origin)
        Returns the DER-encoded certificate (EXPERIMENTAL)
        Parameters:
        origin - Origin to get certificate for
        Returns:
        List of tableNames
      • getCookies

        public static Command<Cookies> getCookies​(java.util.Optional<java.util.List<java.lang.String>> urls)
        Returns all browser cookies for the current URL. Depending on the backend support, will return detailed cookie information in the cookies field
        Parameters:
        urls - The list of URLs for which applicable cookies will be fetched
        Returns:
        Array of cookies
      • getResponseBody

        public static Command<ResponseBody> getResponseBody​(RequestId requestId)
        Returns content served for the given request
        Parameters:
        requestId - Identifier of the network request to get content for
        Returns:
        ResponseBody object
      • getRequestPostData

        public static Command<java.lang.String> getRequestPostData​(RequestId requestId)
        Returns post data sent with the request. Returns an error when no data was sent with the request.
        Parameters:
        requestId - Identifier of the network request to get content for.
        Returns:
        DevTools Command with Request body string, omitting files from multipart requests
      • getResponseBodyForInterception

        @Beta
        public static Command<ResponseBody> getResponseBodyForInterception​(InterceptionId interceptionId)
        Returns content served for the given currently intercepted request (EXPERIMENTAL)
        Parameters:
        interceptionId - Identifier for the intercepted request to get body for
        Returns:
        ResponseBody object
      • takeResponseBodyForInterceptionAsStream

        @Beta
        public static Command<java.lang.String> takeResponseBodyForInterceptionAsStream​(InterceptionId interceptionId)
        Returns a handle to the stream representing the response body. Note that after this command, the intercepted request can't be continued as is -- you either need to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified (EXPERIMENTAL)
        Parameters:
        interceptionId - Identifier for the intercepted request to get body for
        Returns:
        HTTP response body Stream as a String
      • replayXHR

        public static Command<java.lang.Void> replayXHR​(RequestId requestId)
        Parameters:
        requestId - Identifier of XHR to replay
        Returns:
        - DevTools Command
      • searchInResponseBody

        @Beta
        public static Command<java.util.List<SearchMatch>> searchInResponseBody​(RequestId requestId,
                                                                                java.lang.String query,
                                                                                java.util.Optional<java.lang.Boolean> caseSensitive,
                                                                                java.util.Optional<java.lang.Boolean> isRegex)
        Searches for given string in response content (EXPERIMENTAL)
        Parameters:
        requestId - Identifier of the network response to search
        query - String to search for.
        caseSensitive - If true, search is case sensitive
        isRegex - If true, treats string parameter as regex
        Returns:
        List of SearchMatch
      • setBlockedURLs

        @Beta
        public static Command<java.lang.Void> setBlockedURLs​(java.util.List<java.lang.String> urls)
        Blocks URLs from loading (EXPERIMENTAL)
        Parameters:
        urls - URL patterns to block. Wildcards ('*') are allowed.
        Returns:
        DevTools Command
      • setBypassServiceWorker

        @Beta
        public static Command<java.lang.Void> setBypassServiceWorker​(boolean bypass)
        Toggles ignoring of service worker for each request. (EXPERIMENTAL)
        Parameters:
        bypass - Bypass service worker and load from network
        Returns:
        - DevTools Command
      • setCacheDisabled

        public static Command<java.lang.Void> setCacheDisabled​(boolean cacheDisabled)
        Toggles ignoring cache for each request. If true, cache will not be used.
        Parameters:
        cacheDisabled - Cache disabled state.
        Returns:
        DevTools Command
      • setCookie

        public static Command<java.lang.Boolean> setCookie​(org.openqa.selenium.Cookie cookie,
                                                           java.util.Optional<java.lang.String> url)
        Sets a cookie with the given cookie data; may overwrite equivalent cookies if they exist
        Parameters:
        cookie - Cookie object where Name and Value are mandatory
        url - The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie
        Returns:
        Boolean
      • setDataSizeLimitsForTest

        @Beta
        public static Command<java.lang.Void> setDataSizeLimitsForTest​(int maxTotalSize,
                                                                       int maxResourceSize)
        (EXPERIMENTAL)
        Parameters:
        maxTotalSize - Maximum total buffer size
        maxResourceSize - Maximum per-resource size
        Returns:
        DevTools Command
      • setExtraHTTPHeaders

        public static Command<java.lang.Void> setExtraHTTPHeaders​(java.util.Map<java.lang.String,​java.lang.String> headers)
        Specifies whether to always send extra HTTP headers with the requests from this page.
        Parameters:
        headers - Map with extra HTTP headers.
        Returns:
        DevTools Command
      • setRequestInterception

        @Beta
        public static Command<java.lang.Void> setRequestInterception​(java.util.List<RequestPattern> patterns)
        Sets the requests to intercept that match the provided patterns and optionally resource types (EXPERIMENTAL)
        Parameters:
        patterns - Requests matching any of these patterns will be forwarded and wait for the corresponding continueInterceptedRequest call.
        Returns:
        DevTools Command
      • setUserAgentOverride

        public static Command<java.lang.Void> setUserAgentOverride​(java.lang.String userAgent,
                                                                   java.util.Optional<java.lang.String> acceptLanguage,
                                                                   java.util.Optional<java.lang.String> platform)
        Allows overriding user agent with the given string
        Parameters:
        userAgent - User agent to use
        acceptLanguage - Browser langugage to emulate
        platform - The platform navigator.platform should return
        Returns:
        DevTools Command
      • dataReceived

        public static Event<DataReceived> dataReceived()
        Fired when data chunk was received over the network.
        Returns:
        DataReceived Event
      • eventSourceMessageReceived

        public static Event<EventSourceMessageReceived> eventSourceMessageReceived()
        Fired when EventSource message is received
        Returns:
        EventSourceMessageReceived Event
      • loadingFailed

        public static Event<LoadingFailed> loadingFailed()
        Fired when HTTP request has failed to load
        Returns:
        LoadingFailed object
      • loadingFinished

        public static Event<LoadingFinished> loadingFinished()
        Fired when HTTP request has finished loading
        Returns:
        LoadingFinished object
      • requestServedFromCache

        public static Event<RequestId> requestServedFromCache()
        Fired if request ended up loading from cache
        Returns:
        RequestId object
      • resourceChangedPriority

        @Beta
        public static Event<ResourceChangedPriority> resourceChangedPriority()
        Fired when resource loading priority is changed (EXPERIMENTAL)
        Returns:
        ResourceChangedPriority object
      • signedExchangeReceived

        @Beta
        public static Event<SignedExchangeReceived> signedExchangeReceived()
        Fired when a signed exchange was received over the network (EXPERIMENTAL)
        Returns:
        SignedExchangeReceived object
      • requestWillBeSent

        public static Event<RequestWillBeSent> requestWillBeSent()
        Fired when page is about to send HTTP request
        Returns:
        RequestWillBeSent object
      • requestIntercepted

        @Beta
        public static Event<RequestIntercepted> requestIntercepted()
        Details of an intercepted HTTP request, which must be either allowed, blocked, modified or mocked.(EXPERIMENTAL)
        Returns:
        RequestIntercepted Object
      • webSocketFrameError

        public static Event<WebSocketFrameError> webSocketFrameError()
        Fired when WebSocket message error occurs.
      • webSocketCreated

        public static Event<WebSocketCreated> webSocketCreated()
        Fired upon WebSocket creation.
      • webSocketClosed

        public static Event<WebSocketClosed> webSocketClosed()
        Fired upon WebSocket creation.
      • webSocketFrameReceived

        public static Event<WebSocketFrame> webSocketFrameReceived()
        Fired when WebSocket message is received.
      • webSocketFrameSent

        public static Event<WebSocketFrame> webSocketFrameSent()
        Fired when WebSocket message is sent.