Skip to content

CdpBrowserContext

Namespace: PuppeteerSharp.Cdp

public class CdpBrowserContext : BrowserContext, IBrowserContext, IDisposable, IAsyncDisposable

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.

Inheritance: object → BrowserContext

Implements: IBrowserContext, IDisposable, IAsyncDisposable

View source

public override Task ClearPermissionOverridesAsync()

Clears all permission overrides for the browser context.

Returns: Task — The task.

View source

public override Task CloseAsync()

Closes the browser context. All the targets that belong to the browser context will be closed.

Returns: Task — Task.

View source

public override Task<CookieParam[]> GetCookiesAsync()

Gets all cookies in the browser context.

Returns: Task<CookieParam[]> — Task which resolves to an array of CookieParam.

View source

public override Task<IPage> NewPageAsync(CreatePageOptions options = null)

Creates a new page.

Parameters

Name Type Description
options CreatePageOptions Options for creating the page.

Returns: Task<IPage> — Task which resolves to a new IPage object.

View source

OverridePermissionsAsync(string, IEnumerable<OverridePermission>)

Section titled “OverridePermissionsAsync(string, IEnumerable<OverridePermission>)”
public override Task OverridePermissionsAsync(string origin, IEnumerable<OverridePermission> permissions)

Overrides the browser context permissions.

Parameters

Name Type Description
origin string The origin to grant permissions to, e.g. “https://example.com”.
permissions IEnumerable<OverridePermission> An array of permissions to grant. All permissions that are not listed here will be automatically denied.

Returns: Task — The task.

Example

var context = browser.DefaultBrowserContext; await context.OverridePermissionsAsync(“https://html5demos.com”, new List<string> {“geolocation”});

View source

public override Task<IPage[]> PagesAsync(bool includeAll = false)

An array of all pages inside the browser context.

Parameters

Name Type Description
includeAll bool Experimental. When true, includes all kinds of pages.

Returns: Task<IPage[]> — Task which resolves to an array of all open pages. Non visible pages, such as "background_page", will not be listed here. You can find them using PageAsync().

View source

public override Task SetCookieAsync(params CookieData[] cookies)

Sets cookies in the browser context.

Parameters

Name Type Description
cookies CookieData\[\] Cookies to set.

Returns: Task — Task.

View source

SetPermissionAsync(string, params PermissionEntry[])

Section titled “SetPermissionAsync(string, params PermissionEntry[])”
public override Task SetPermissionAsync(string origin, params PermissionEntry[] permissions)

Sets the permission for a specific origin.

Parameters

Name Type Description
origin string The origin to set the permission for, e.g. “https://example.com”. Use “*” for all origins (CDP only).
permissions PermissionEntry\[\] The permissions to set.

Returns: Task — The task.

View source

public override ITarget[] Targets()

Gets an array of all active targets inside the browser context.

Returns: ITarget\[\] — An array of all active targets inside the browser context.

View source

Made with love by Dario Kondratiuk