Fetch

class Fetch(cdp: CDP) : Domain

A domain for letting clients substitute browser's network layer with client code.

Constructors

Link copied to clipboard
constructor(cdp: CDP)

Types

Link copied to clipboard
@Serializable
data class AuthChallenge(val source: String? = null, val origin: String, val scheme: String, val realm: String)

Authorization challenge for HTTP status code 401 or 407.

Link copied to clipboard
@Serializable
data class AuthChallengeResponse(val response: String, val username: String? = null, val password: String? = null)

Response to an AuthChallenge.

Link copied to clipboard
@Serializable
data class AuthRequiredParameter(val requestId: String, val request: Network.Request, val frameId: String, val resourceType: Network.ResourceType, val authChallenge: Fetch.AuthChallenge)

Issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.

Link copied to clipboard
@Serializable
data class ContinueRequestParameter(val requestId: String, val url: String? = null, val method: String? = null, val postData: String? = null, val headers: List<Fetch.HeaderEntry>? = null, val interceptResponse: Boolean? = null)
Link copied to clipboard
@Serializable
data class ContinueResponseParameter(val requestId: String, val responseCode: Int? = null, val responsePhrase: String? = null, val responseHeaders: List<Fetch.HeaderEntry>? = null, val binaryResponseHeaders: String? = null)
Link copied to clipboard
@Serializable
data class ContinueWithAuthParameter(val requestId: String, val authChallengeResponse: Fetch.AuthChallengeResponse)
Link copied to clipboard
@Serializable
data class EnableParameter(val patterns: List<Fetch.RequestPattern>? = null, val handleAuthRequests: Boolean? = null)
Link copied to clipboard
@Serializable
data class FailRequestParameter(val requestId: String, val errorReason: Network.ErrorReason)
Link copied to clipboard
@Serializable
data class FulfillRequestParameter(val requestId: String, val responseCode: Int, val responseHeaders: List<Fetch.HeaderEntry>? = null, val binaryResponseHeaders: String? = null, val body: String? = null, val responsePhrase: String? = null)
Link copied to clipboard
@Serializable
data class GetResponseBodyParameter(val requestId: String)
Link copied to clipboard
@Serializable
data class GetResponseBodyReturn(val body: String, val base64Encoded: Boolean)
Link copied to clipboard
@Serializable
data class HeaderEntry(val name: String, val value: String)

Response HTTP header entry

Link copied to clipboard
@Serializable
data class RequestPattern(val urlPattern: String? = null, val resourceType: Network.ResourceType? = null, val requestStage: Fetch.RequestStage? = null)
Link copied to clipboard
@Serializable
data class RequestPausedParameter(val requestId: String, val request: Network.Request, val frameId: String, val resourceType: Network.ResourceType, val responseErrorReason: Network.ErrorReason? = null, val responseStatusCode: Int? = null, val responseStatusText: String? = null, val responseHeaders: List<Fetch.HeaderEntry>? = null, val networkId: String? = null, val redirectedRequestId: String? = null)

Issued when the domain is enabled and the request URL matches the specified filter. The request is paused until the client responds with one of continueRequest, failRequest or fulfillRequest. The stage of the request can be determined by presence of responseErrorReason and responseStatusCode -- the request is at the response stage if either of these fields is present and in the request stage otherwise. Redirect responses and subsequent requests are reported similarly to regular responses and requests. Redirect responses may be distinguished by the value of responseStatusCode (which is one of 301, 302, 303, 307, 308) along with presence of the location header. Requests resulting from a redirect will have redirectedRequestId field set.

Link copied to clipboard
@Serializable
enum RequestStage : Enum<Fetch.RequestStage>

Stages of the request to handle. Request will intercept before the request is sent. Response will intercept after the response is received (but before response body is received).

Link copied to clipboard
@Serializable
data class TakeResponseBodyAsStreamParameter(val requestId: String)
Link copied to clipboard
@Serializable
data class TakeResponseBodyAsStreamReturn(val stream: String)

Properties

Link copied to clipboard

Issued when the domain is enabled with handleAuthRequests set to true. The request is paused until client responds with continueWithAuth.

Link copied to clipboard

Issued when the domain is enabled and the request URL matches the specified filter. The request is paused until the client responds with one of continueRequest, failRequest or fulfillRequest. The stage of the request can be determined by presence of responseErrorReason and responseStatusCode -- the request is at the response stage if either of these fields is present and in the request stage otherwise. Redirect responses and subsequent requests are reported similarly to regular responses and requests. Redirect responses may be distinguished by the value of responseStatusCode (which is one of 301, 302, 303, 307, 308) along with presence of the location header. Requests resulting from a redirect will have redirectedRequestId field set.

Functions

Link copied to clipboard
suspend fun continueRequest(args: Fetch.ContinueRequestParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun continueRequest(requestId: String, url: String? = null, method: String? = null, postData: String? = null, headers: List<Fetch.HeaderEntry>? = null, interceptResponse: Boolean? = null)

Continues the request, optionally modifying some of its parameters.

Link copied to clipboard
suspend fun continueResponse(args: Fetch.ContinueResponseParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun continueResponse(requestId: String, responseCode: Int? = null, responsePhrase: String? = null, responseHeaders: List<Fetch.HeaderEntry>? = null, binaryResponseHeaders: String? = null)

Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.

Link copied to clipboard
suspend fun continueWithAuth(args: Fetch.ContinueWithAuthParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun continueWithAuth(requestId: String, authChallengeResponse: Fetch.AuthChallengeResponse)

Continues a request supplying authChallengeResponse following authRequired event.

Link copied to clipboard
suspend fun disable(mode: CommandMode = CommandMode.DEFAULT)

Disables the fetch domain.

Link copied to clipboard
suspend fun enable(args: Fetch.EnableParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun enable(patterns: List<Fetch.RequestPattern>? = null, handleAuthRequests: Boolean? = null)

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

Link copied to clipboard
suspend fun failRequest(args: Fetch.FailRequestParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun failRequest(requestId: String, errorReason: Network.ErrorReason)

Causes the request to fail with specified reason.

Link copied to clipboard
suspend fun fulfillRequest(args: Fetch.FulfillRequestParameter, mode: CommandMode = CommandMode.DEFAULT)
suspend fun fulfillRequest(requestId: String, responseCode: Int, responseHeaders: List<Fetch.HeaderEntry>? = null, binaryResponseHeaders: String? = null, body: String? = null, responsePhrase: String? = null)

Provides response to the request.

Link copied to clipboard

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. Note that the response body is not available for redirects. Requests paused in the redirect received state may be differentiated by responseCode and presence of location response header, see comments to requestPaused for details.

Link copied to clipboard

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.