Table of Contents

Interface IRequest

Namespace
PuppeteerSharp
Assembly
PuppeteerSharp.dll

Whenever the page sends a request, the following events are emitted by puppeteer's page: Request emitted when the request is issued by the page. Response emitted when/if the response is received for the request. RequestFinished emitted when the response body is downloaded and the request is complete.

If request fails at some point, then instead of RequestFinished event (and possibly instead of Response event), the RequestFailed event is emitted.

If request gets a 'redirect' response, the request is successfully finished with the RequestFinished event, and a new request is issued to a redirected url.

public interface IRequest

Properties

Failure

Gets the failure.

string Failure { get; }

Property Value

string

The failure.

Frame

Gets the frame.

IFrame Frame { get; }

Property Value

IFrame

The frame.

HasPostData

True when the request has POST data. Note that PostData might still be null when this flag is true when the data is too long or not readily available in the decoded form. In that case, use FetchPostDataAsync().

bool HasPostData { get; }

Property Value

bool

Headers

Gets the HTTP headers.

Dictionary<string, string> Headers { get; }

Property Value

Dictionary<string, string>

HTTP headers.

Initiator

Information about the request initiator.

Initiator Initiator { get; }

Property Value

Initiator

InterceptionId

Gets the interception identifier.

string InterceptionId { get; }

Property Value

string

The interception identifier.

IsNavigationRequest

Gets whether this request is driving frame's navigation.

bool IsNavigationRequest { get; }

Property Value

bool

Method

Gets the HTTP method.

HttpMethod Method { get; }

Property Value

HttpMethod

HTTP method.

PostData

Gets the post data.

object PostData { get; }

Property Value

object

The post data.

RedirectChain

A redirectChain is a chain of requests initiated to fetch a resource. If there are no redirects and the request was successful, the chain will be empty. If a server responds with at least a single redirect, then the chain will contain all the requests that were redirected. redirectChain is shared between all the requests of the same chain.

IRequest[] RedirectChain { get; }

Property Value

IRequest[]

The redirect chain.

Examples

For example, if the website http://example.com has a single redirect to https://example.com, then the chain will contain one request:

var response = await page.GoToAsync("http://example.com");
var chain = response.Request.RedirectChain;
Console.WriteLine(chain.Length); // 1
Console.WriteLine(chain[0].Url); // 'http://example.com'

If the website https://google.com has no redirects, then the chain will be empty:

var response = await page.GoToAsync("https://google.com");
var chain = response.Request.RedirectChain;
Console.WriteLine(chain.Length); // 0

RequestId

Gets the request identifier.

string RequestId { get; }

Property Value

string

The request identifier.

ResourceType

Gets the type of the resource.

ResourceType ResourceType { get; }

Property Value

ResourceType

The type of the resource.

Response

Response attached to the request.

IResponse Response { get; }

Property Value

IResponse

The response.

Url

Gets the URL.

string Url { get; }

Property Value

string

The URL.

Methods

AbortAsync(RequestAbortErrorCode, int?)

Aborts request. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is immediately thrown if the request interception is not enabled.

Task AbortAsync(RequestAbortErrorCode errorCode = RequestAbortErrorCode.Failed, int? priority = null)

Parameters

errorCode RequestAbortErrorCode

Optional error code. Defaults to Failed.

priority int?

Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using AddRequestInterceptor(Func<IRequest, Task>) instead of Request.

Returns

Task

Task.

ContinueAsync(Payload, int?)

Continues request with optional request overrides. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is immediately thrown if the request interception is not enabled. If the URL is set it won't perform a redirect. The request will be silently forwarded to the new url. For example, the address bar will show the original url.

Task ContinueAsync(Payload payloadOverrides = null, int? priority = null)

Parameters

payloadOverrides Payload

Optional request overwrites.

priority int?

Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using AddRequestInterceptor(Func<IRequest, Task>) instead of Request.

Returns

Task

Task.

FetchPostDataAsync()

Fetches the POST data for the request from the browser.

Task<string> FetchPostDataAsync()

Returns

Task<string>

Task which resolves to the request's POST data.

RespondAsync(ResponseData, int?)

Fulfills request with given response. To use this, request interception should be enabled with SetRequestInterceptionAsync(bool). Exception is thrown if request interception is not enabled.

Task RespondAsync(ResponseData response, int? priority = null)

Parameters

response ResponseData

Response that will fulfill this request.

priority int?

Optional intercept abort priority. If provided, intercept will be resolved using cooperative handling rules. Otherwise, intercept will be resolved immediately. IMPORTANT: If you set the priority, you will need to attach Request listener using AddRequestInterceptor(Func<IRequest, Task>) instead of Request.

Returns

Task

Task.