Skip to content

BidiBrowser

Namespace: PuppeteerSharp.Bidi

public class BidiBrowser : Browser, IBrowser, IDisposable, IAsyncDisposable

Represents a browser connected using the Bidi protocol.

Inheritance: object → Browser

Implements: IBrowser, IDisposable, IAsyncDisposable

View source

public override DebugInfo DebugInfo { get; }

Get debug information from Puppeteer.

Value: DebugInfo

Currently, includes pending protocol calls. In the future, more info might be added.

View source

public override IBrowserContext DefaultContext { get; }

Returns the default browser context. The default browser context can not be closed.

Value: IBrowserContext — The default context.

View source

public override bool IsClosed { get; }

Gets a value indicating if the browser is closed.

Value: bool

View source

public override bool IsConnected { get; }

Indicates that the browser is connected.

Value: bool

View source

public override ITarget Target { get; }

A target associated with the browser.

Value: ITarget

View source

public override string WebSocketEndpoint { get; }

Gets the Browser websocket url.

Value: string

Browser websocket endpoint which can be used as an argument to ILoggerFactory). The format is ws://${host}:${port}/devtools/browser/[id] You can find the webSocketDebuggerUrl from http://${host}:${port}/json/version. Learn more about the devtools protocol <a href=“https://chromedevtools.github.io/devtools-protocol"&gt;https://chromedevtools.github.io/devtools-protocol&lt;/a> and the browser endpoint <a href=“https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target"&gt;https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target&lt;/a>.

View source

public override Task<ScreenInfo> AddScreenAsync(AddScreenParams @params)

Adds a new screen with specified parameters and returns a ScreenInfo object, including the new screen’s ID.

Parameters

Name Type Description
params AddScreenParams The parameters for the new screen.

Returns: Task<ScreenInfo> — A task that resolves to the added screen information.

Only supported in headless mode.

View source

public override IBrowserContext[] BrowserContexts()

Returns an array of all open IBrowserContext. In a newly created browser, this will return a single instance of IBrowserContext.

Returns: IBrowserContext\[\] — An array of IBrowserContext objects.

View source

public override Task CloseAsync()

Closes Chromium and all of its pages (if any were opened). The browser object itself is considered disposed and cannot be used anymore.

Returns: Task — Task.

View source

CreateBrowserContextAsync(BrowserContextOptions)

Section titled “CreateBrowserContextAsync(BrowserContextOptions)”
public override Task<IBrowserContext> CreateBrowserContextAsync(BrowserContextOptions options = null)

Creates a new browser context. This won’t share cookies/cache with other browser contexts.

Parameters

Name Type Description
options BrowserContextOptions Options.

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

Example

using(var browser = await Puppeteer.LaunchAsync(new LaunchOptions()))
{
// Create a new browser context.
var context = await browser.CreateBrowserContextAsync();
// Create a new page in a pristine context.
var page = await context.NewPageAsync();
// Do stuff
await page.GoToAsync("https://example.com");
}

View source

public override void Disconnect()

Disconnects Puppeteer from the browser, but leaves the process running. After calling Disconnect(), the browser object is considered disposed and cannot be used anymore.

View source

public override Task<IReadOnlyDictionary<string, Extension>> ExtensionsAsync()

Returns a map of installed extensions, keyed by extension ID.

Returns: Task<IReadOnlyDictionary<string, Extension>> — A task that resolves to a dictionary of extension ID to Extension.

View source

public override Task<PWAState> GetPWAStateAsync(GetPWAStateOptions options)

Returns the OS-integration state of an installed Progressive Web App (PWA), such as its badge count and registered file handlers.

Parameters

Name Type Description
options GetPWAStateOptions Options for querying the PWA state.

Returns: Task<PWAState> — A task that resolves to the PWA state.

Only available over a pipe connection. See InstallPWAAsync(InstallPWAOptions). Meaningful only for an app that is currently installed; querying an unknown manifest id rejects.

View source

public override Task<string> GetUserAgentAsync()

Gets the browser’s original user agent.

Returns: Task<string> — Task which resolves to the browser’s original user agent.

Pages can override browser user agent with UserAgentMetadata).

View source

public override Task<string> GetVersionAsync()

Gets the browser’s version.

Returns: Task<string> — For headless Chromium, this is similar to HeadlessChrome/61.0.3153.0. For non-headless, this is similar to Chrome/61.0.3153.0.

the format of GetVersionAsync() might change with future releases of Chromium.

View source

public override Task<WindowBounds> GetWindowBoundsAsync(string windowId)

Gets the specified window bounds.

Parameters

Name Type Description
windowId string The window ID.

Returns: Task<WindowBounds> — A task that resolves to the WindowBounds.

View source

InstallExtensionAsync(string, ExtensionInstallOptions)

Section titled “InstallExtensionAsync(string, ExtensionInstallOptions)”
public override Task<string> InstallExtensionAsync(string path, ExtensionInstallOptions options = null)

Installs an unpacked extension and returns the extension ID.

Parameters

Name Type Description
path string The path to the unpacked extension directory.
options ExtensionInstallOptions Options for installing the extension.

Returns: Task<string> — A task that resolves to the extension ID.

View source

public override Task<string> InstallPWAAsync(InstallPWAOptions options)

Installs a Progressive Web App (PWA) and returns its manifest id.

Parameters

Name Type Description
options InstallPWAOptions Options for installing the PWA.

Returns: Task<string> — A task that resolves to the manifest id.

Only available when connected to the browser over a pipe connection. Set Pipe to true; it defaults to false. The underlying PWA CDP domain is not exposed over a WebSocket connection. The returned manifest id echoes ManifestId, so it can be passed directly to LaunchPWAAsync(LaunchPWAOptions), GetPWAStateAsync(GetPWAStateOptions), or UninstallPWAAsync(UninstallPWAOptions).

View source

public override Task<IPage> LaunchPWAAsync(LaunchPWAOptions options)

Launches an installed Progressive Web App (PWA) and resolves with the IPage backing the app window.

Parameters

Name Type Description
options LaunchPWAOptions Options for launching the PWA.

Returns: Task<IPage> — A task that resolves to the page backing the app window.

Only available over a pipe connection. See InstallPWAAsync(InstallPWAOptions). PWA.launch resolves with the id of the launched tab target. Puppeteer does not expose tab targets through Targets(); this method instead resolves with the tab’s child page target (the app’s web contents). If Chromium focuses an existing app window, this returns that window’s existing page.

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

public override Task RemoveScreenAsync(string screenId)

Removes the screen associated with the given screen ID, unless it is the primary screen.

Parameters

Name Type Description
screenId string The ID of the screen to remove.

Returns: Task — A task that completes when the screen is removed.

Only supported in headless mode. Fails if the primary screen ID is specified.

View source

public override Task<ScreenInfo[]> ScreensAsync()

Gets a list of ScreenInfo objects.

Returns: Task<ScreenInfo[]> — A task that resolves to an array of screen information objects.

View source

SetWindowBoundsAsync(string, WindowBounds)

Section titled “SetWindowBoundsAsync(string, WindowBounds)”
public override Task SetWindowBoundsAsync(string windowId, WindowBounds windowBounds)

Sets the specified window bounds.

Parameters

Name Type Description
windowId string The window ID.
windowBounds WindowBounds The bounds to set.

Returns: Task — A task that resolves when the bounds have been set.

View source

public override ITarget[] Targets()

Returns An Array of all active targets.

Returns: ITarget\[\] — An Array of all active targets.

View source

public override Task UninstallExtensionAsync(string id)

Uninstalls a previously installed extension by its ID.

Parameters

Name Type Description
id string The extension ID to uninstall.

Returns: Task — A task that completes when the extension is uninstalled.

View source

public override Task UninstallPWAAsync(UninstallPWAOptions options)

Uninstalls a previously installed Progressive Web App (PWA).

Parameters

Name Type Description
options UninstallPWAOptions Options for uninstalling the PWA.

Returns: Task — A task that completes when the PWA is uninstalled.

Only available over a pipe connection. See InstallPWAAsync(InstallPWAOptions).

View source

Made with love by Dario Kondratiuk