Table of Contents

Interface IFetch

Namespace
Selenium.WebDriver.BiDi.Cdp.Fetch
Assembly
Selenium.WebDriver.BiDi.Cdp.dll

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

public interface IFetch

Properties

AuthRequired

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

IEventSource<AuthRequiredEventArgs> AuthRequired { get; }

Property Value

IEventSource<AuthRequiredEventArgs>

Remarks

Event args (AuthRequiredEventArgs):

  • RequestId - Each request the page makes will have a unique id.
  • Request - The details of the request.
  • FrameId - The id of the frame that initiated the request.
  • ResourceType - How the requested resource will be used.
  • AuthChallenge - Details of the Authorization Challenge encountered. If this is set, client should respond with continueRequest that contains AuthChallengeResponse.

RequestPaused

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.

IEventSource<RequestPausedEventArgs> RequestPaused { get; }

Property Value

IEventSource<RequestPausedEventArgs>

Remarks

Event args (RequestPausedEventArgs):

  • RequestId - Each request the page makes will have a unique id.
  • Request - The details of the request.
  • FrameId - The id of the frame that initiated the request.
  • ResourceType - How the requested resource will be used.
  • ResponseErrorReason - Response error if intercepted at response stage.
  • ResponseStatusCode - Response code if intercepted at response stage.
  • ResponseStatusText - Response status text if intercepted at response stage.
  • ResponseHeaders - Response headers if intercepted at the response stage.
  • NetworkId - If the intercepted request had a corresponding Network.requestWillBeSent event fired for it, then this networkId will be the same as the requestId present in the requestWillBeSent event.
  • RedirectedRequestId - If the request is due to a redirect response from the server, the id of the request that has caused the redirect.

Methods

ContinueRequestAsync(RequestId, string?, string?, string?, ImmutableArray<HeaderEntry>?, bool?, string?, CancellationToken)

Continues the request, optionally modifying some of its parameters.

Task<ContinueRequestResult> ContinueRequestAsync(RequestId requestId, string? url = null, string? method = null, string? postData = null, ImmutableArray<HeaderEntry>? headers = null, bool? interceptResponse = null, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

An id the client received in requestPaused event.

url string

If set, the request url will be modified in a way that's not observable by page.

method string

If set, the request method is overridden.

postData string

If set, overrides the post data in the request. (Encoded as a base64 string when passed over JSON)

headers ImmutableArray<HeaderEntry>?

If set, overrides the request headers. Note that the overrides do not extend to subsequent redirect hops, if a redirect happens. Another override may be applied to a different request produced by a redirect.

interceptResponse bool?

If set, overrides response interception behavior for this request.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<ContinueRequestResult>

A task representing the asynchronous operation, containing a ContinueRequestResult.

ContinueResponseAsync(RequestId, long?, string?, ImmutableArray<HeaderEntry>?, string?, string?, CancellationToken)

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

[Experimental("BIDICDP001")]
Task<ContinueResponseResult> ContinueResponseAsync(RequestId requestId, long? responseCode = null, string? responsePhrase = null, ImmutableArray<HeaderEntry>? responseHeaders = null, string? binaryResponseHeaders = null, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

An id the client received in requestPaused event.

responseCode long?

An HTTP response code. If absent, original response code will be used.

responsePhrase string

A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.

responseHeaders ImmutableArray<HeaderEntry>?

Response headers. If absent, original response headers will be used.

binaryResponseHeaders string

Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<ContinueResponseResult>

A task representing the asynchronous operation, containing a ContinueResponseResult.

ContinueWithAuthAsync(RequestId, AuthChallengeResponse, string?, CancellationToken)

Continues a request supplying authChallengeResponse following authRequired event.

Task<ContinueWithAuthResult> ContinueWithAuthAsync(RequestId requestId, AuthChallengeResponse authChallengeResponse, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

An id the client received in authRequired event.

authChallengeResponse AuthChallengeResponse

Response to with an authChallenge.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<ContinueWithAuthResult>

A task representing the asynchronous operation, containing a ContinueWithAuthResult.

DisableAsync(string?, CancellationToken)

Disables the fetch domain.

Task<DisableResult> DisableAsync(string? session = null, CancellationToken cancellationToken = default)

Parameters

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<DisableResult>

A task representing the asynchronous operation, containing a DisableResult.

EnableAsync(ImmutableArray<RequestPattern>?, bool?, string?, CancellationToken)

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

Task<EnableResult> EnableAsync(ImmutableArray<RequestPattern>? patterns = null, bool? handleAuthRequests = null, string? session = null, CancellationToken cancellationToken = default)

Parameters

patterns ImmutableArray<RequestPattern>?

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 bool?

If true, authRequired events will be issued and requests will be paused expecting a call to continueWithAuth.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<EnableResult>

A task representing the asynchronous operation, containing a EnableResult.

FailRequestAsync(RequestId, ErrorReason, string?, CancellationToken)

Causes the request to fail with specified reason.

Task<FailRequestResult> FailRequestAsync(RequestId requestId, ErrorReason errorReason, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

An id the client received in requestPaused event.

errorReason ErrorReason

Causes the request to fail with the given reason.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<FailRequestResult>

A task representing the asynchronous operation, containing a FailRequestResult.

FulfillRequestAsync(RequestId, long, ImmutableArray<HeaderEntry>?, string?, string?, string?, string?, CancellationToken)

Provides response to the request.

Task<FulfillRequestResult> FulfillRequestAsync(RequestId requestId, long responseCode, ImmutableArray<HeaderEntry>? responseHeaders = null, string? binaryResponseHeaders = null, string? body = null, string? responsePhrase = null, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

An id the client received in requestPaused event.

responseCode long

An HTTP response code.

responseHeaders ImmutableArray<HeaderEntry>?

Response headers.

binaryResponseHeaders string

Alternative way of specifying response headers as a \0-separated series of name: value pairs. Prefer the above method unless you need to represent some non-UTF8 values that can't be transmitted over the protocol as text. (Encoded as a base64 string when passed over JSON)

body string

A response body. If absent, original response body will be used if the request is intercepted at the response stage and empty body will be used if the request is intercepted at the request stage. (Encoded as a base64 string when passed over JSON)

responsePhrase string

A textual representation of responseCode. If absent, a standard phrase matching responseCode is used.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<FulfillRequestResult>

A task representing the asynchronous operation, containing a FulfillRequestResult.

GetResponseBodyAsync(RequestId, string?, CancellationToken)

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.

Task<GetResponseBodyResult> GetResponseBodyAsync(RequestId requestId, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId

Identifier for the intercepted request to get body for.

session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<GetResponseBodyResult>

A task representing the asynchronous operation, containing a GetResponseBodyResult.

TakeResponseBodyAsStreamAsync(RequestId, string?, CancellationToken)

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.

Task<TakeResponseBodyAsStreamResult> TakeResponseBodyAsStreamAsync(RequestId requestId, string? session = null, CancellationToken cancellationToken = default)

Parameters

requestId RequestId
session string

Optional CDP session override.

cancellationToken CancellationToken

A token to cancel the asynchronous operation.

Returns

Task<TakeResponseBodyAsStreamResult>

A task representing the asynchronous operation, containing a TakeResponseBodyAsStreamResult.