BidiBrowser
Namespace: PuppeteerSharp.Bidi
public class BidiBrowser : Browser, IBrowser, IDisposable, IAsyncDisposableRepresents a browser connected using the Bidi protocol.
Implements: IBrowser, IDisposable, IAsyncDisposable
Properties
Section titled “Properties”DebugInfo
Section titled “DebugInfo”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.
DefaultContext
Section titled “DefaultContext”public override IBrowserContext DefaultContext { get; }Returns the default browser context. The default browser context can not be closed.
Value: IBrowserContext — The default context.
IsClosed
Section titled “IsClosed”public override bool IsClosed { get; }Gets a value indicating if the browser is closed.
Value: bool
IsConnected
Section titled “IsConnected”public override bool IsConnected { get; }Indicates that the browser is connected.
Value: bool
Target
Section titled “Target”public override ITarget Target { get; }A target associated with the browser.
Value: ITarget
WebSocketEndpoint
Section titled “WebSocketEndpoint”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">https://chromedevtools.github.io/devtools-protocol</a>
and the browser endpoint <a href=“https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target">https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target</a>.
Methods
Section titled “Methods”AddScreenAsync(AddScreenParams)
Section titled “AddScreenAsync(AddScreenParams)”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.
BrowserContexts()
Section titled “BrowserContexts()”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.
CloseAsync()
Section titled “CloseAsync()”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.
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");}Disconnect()
Section titled “Disconnect()”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.
ExtensionsAsync()
Section titled “ExtensionsAsync()”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.
GetPWAStateAsync(GetPWAStateOptions)
Section titled “GetPWAStateAsync(GetPWAStateOptions)”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.
GetUserAgentAsync()
Section titled “GetUserAgentAsync()”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).
GetVersionAsync()
Section titled “GetVersionAsync()”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.
GetWindowBoundsAsync(string)
Section titled “GetWindowBoundsAsync(string)”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.
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.
InstallPWAAsync(InstallPWAOptions)
Section titled “InstallPWAAsync(InstallPWAOptions)”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).
LaunchPWAAsync(LaunchPWAOptions)
Section titled “LaunchPWAAsync(LaunchPWAOptions)”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.
NewPageAsync(CreatePageOptions)
Section titled “NewPageAsync(CreatePageOptions)”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.
RemoveScreenAsync(string)
Section titled “RemoveScreenAsync(string)”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.
ScreensAsync()
Section titled “ScreensAsync()”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.
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.
Targets()
Section titled “Targets()”public override ITarget[] Targets()Returns An Array of all active targets.
Returns: ITarget\[\] — An Array of all active targets.
UninstallExtensionAsync(string)
Section titled “UninstallExtensionAsync(string)”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.
UninstallPWAAsync(UninstallPWAOptions)
Section titled “UninstallPWAAsync(UninstallPWAOptions)”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).
Made with love by Dario Kondratiuk