Table of Contents

Class Request

Namespace
PuppeteerSharp
Assembly
PuppeteerSharp.dll

Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy.

public class Request : IRequest
Inheritance
Request
Implements

Properties

Failure

Gets the failure.

public string Failure { get; }

Property Value

string

The failure.

Frame

Gets the frame.

public 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().

public bool HasPostData { get; }

Property Value

bool

Headers

Gets the HTTP headers.

public Dictionary<string, string> Headers { get; }

Property Value

Dictionary<string, string>

HTTP headers.

Initiator

Information about the request initiator.

public Initiator Initiator { get; }

Property Value

Initiator

InterceptionId

Gets the interception identifier.

public string InterceptionId { get; }

Property Value

string

The interception identifier.

IsNavigationRequest

Gets whether this request is driving frame's navigation.

public bool IsNavigationRequest { get; }

Property Value

bool

Method

Gets the HTTP method.

public HttpMethod Method { get; }

Property Value

HttpMethod

HTTP method.

PostData

Gets the post data.

public 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.

public 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.

public string RequestId { get; }

Property Value

string

The request identifier.

ResourceType

Gets the type of the resource.

public ResourceType ResourceType { get; }

Property Value

ResourceType

The type of the resource.

Response

public Response Response { get; }

Property Value

Response

Url

Gets the URL.

public 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.

public 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.

public Task ContinueAsync(Payload overrides = null, int? priority = null)

Parameters

overrides Payload
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.

public 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.

public 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.