Interface Fetch


  • public interface Fetch
    A domain for letting clients substitute browser's network layer with client code
    • Method Summary

      Modifier and Type Method Description
      void continueRequest​(java.lang.String requestId)
      Continues the request, optionally modifying some of its parameters.
      void continueRequest​(java.lang.String requestId, java.lang.String url, java.lang.String method, java.lang.String postData, java.util.List<HeaderEntry> headers)
      Continues the request, optionally modifying some of its parameters.
      void continueWithAuth​(java.lang.String requestId, AuthChallengeResponse authChallengeResponse)
      Continues a request supplying authChallengeResponse following authRequired event.
      void disable()
      Disables the fetch domain.
      void enable()
      Enables issuing of requestPaused events.
      void enable​(java.util.List<RequestPattern> patterns, java.lang.Boolean handleAuthRequests)
      Enables issuing of requestPaused events.
      void failRequest​(java.lang.String requestId, ErrorReason errorReason)
      Causes the request to fail with specified reason.
      void fulfillRequest​(java.lang.String requestId, java.lang.Integer responseCode, java.util.List<HeaderEntry> responseHeaders)
      Provides response to the request.
      void fulfillRequest​(java.lang.String requestId, java.lang.Integer responseCode, java.util.List<HeaderEntry> responseHeaders, java.lang.String body, java.lang.String responsePhrase)
      Provides response to the request.
      GetResponseBodyResult getResponseBody​(java.lang.String requestId)
      Causes the body of the response to be received from the server and returned as a single string.
      java.lang.String takeResponseBodyAsStream​(java.lang.String requestId)
      Returns a handle to the stream representing the response body.
    • Method Detail

      • disable

        void disable()
        Disables the fetch domain.
      • enable

        void enable​(java.util.List<RequestPattern> patterns,
                    java.lang.Boolean handleAuthRequests)
        Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
        Parameters:
        patterns - If specified, only requests matching any of these patterns will produce fetchRequested event and will be paused until clients response. If not set, all requests will be affected.
        handleAuthRequests - If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth.
      • failRequest

        void failRequest​(java.lang.String requestId,
                         ErrorReason errorReason)
        Causes the request to fail with specified reason.
        Parameters:
        requestId - An id the client received in requestPaused event.
        errorReason - Causes the request to fail with the given reason.
      • fulfillRequest

        void fulfillRequest​(java.lang.String requestId,
                            java.lang.Integer responseCode,
                            java.util.List<HeaderEntry> responseHeaders,
                            java.lang.String body,
                            java.lang.String responsePhrase)
        Provides response to the request.
        Parameters:
        requestId - An id the client received in requestPaused event.
        responseCode - An HTTP response code.
        responseHeaders - Response headers.
        body - A response body.
        responsePhrase - A textual representation of responseCode. If absent, a standard phrase mathcing responseCode is used.
      • continueRequest

        void continueRequest​(java.lang.String requestId,
                             java.lang.String url,
                             java.lang.String method,
                             java.lang.String postData,
                             java.util.List<HeaderEntry> headers)
        Continues the request, optionally modifying some of its parameters.
        Parameters:
        requestId - An id the client received in requestPaused event.
        url - If set, the request url will be modified in a way that's not observable by page.
        method - If set, the request method is overridden.
        postData - If set, overrides the post data in the request.
        headers - If set, overrides the request headrts.
      • continueWithAuth

        void continueWithAuth​(java.lang.String requestId,
                              AuthChallengeResponse authChallengeResponse)
        Continues a request supplying authChallengeResponse following authRequired event.
        Parameters:
        requestId - An id the client received in authRequired event.
        authChallengeResponse - Response to with an authChallenge.
      • getResponseBody

        GetResponseBodyResult getResponseBody​(java.lang.String requestId)
        Causes the body of the response to be received from the server and returned as a single string. May only be issued for a request that is paused in the Response stage and is mutually exclusive with takeResponseBodyForInterceptionAsStream. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.
        Parameters:
        requestId - Identifier for the intercepted request to get body for.
        Returns:
        GetResponseBodyResult
      • takeResponseBodyAsStream

        java.lang.String takeResponseBodyAsStream​(java.lang.String requestId)
        Returns a handle to the stream representing the response body. The request must be paused in the HeadersReceived stage. Note that after this command the request can't be continued as is -- client either needs to cancel it or to provide the response body. The stream only supports sequential read, IO.read will fail if the position is specified. This method is mutually exclusive with getResponseBody. Calling other methods that affect the request or disabling fetch domain before body is received results in an undefined behavior.
      • enable

        void enable()
        Enables issuing of requestPaused events. A request will be paused until client calls one of failRequest, fulfillRequest or continueRequest/continueWithAuth.
      • fulfillRequest

        void fulfillRequest​(java.lang.String requestId,
                            java.lang.Integer responseCode,
                            java.util.List<HeaderEntry> responseHeaders)
        Provides response to the request.
        Parameters:
        requestId - An id the client received in requestPaused event.
        responseCode - An HTTP response code.
        responseHeaders - Response headers.
      • continueRequest

        void continueRequest​(java.lang.String requestId)
        Continues the request, optionally modifying some of its parameters.
        Parameters:
        requestId - An id the client received in requestPaused event.