Class CdpBrowser
- Namespace
- PuppeteerSharp.Cdp
- 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 CdpBrowser : Browser, IBrowser, IDisposable, IAsyncDisposable
- Inheritance
-
CdpBrowser
- Implements
Properties
DebugInfo
Get debug information from Puppeteer.
public override DebugInfo DebugInfo { get; }
Property Value
Remarks
Currently, includes pending protocol calls. In the future, more info might be added.
IsClosed
Gets a value indicating if the browser is closed.
public override bool IsClosed { get; }
Property Value
Methods
AddScreenAsync(AddScreenParams)
Adds a new screen with specified parameters and returns a ScreenInfo object, including the new screen's ID.
public override Task<ScreenInfo> AddScreenAsync(AddScreenParams @params)
Parameters
paramsAddScreenParamsThe parameters for the new screen.
Returns
- Task<ScreenInfo>
A task that resolves to the added screen information.
Remarks
Only supported in headless mode.
BrowserContexts()
Returns an array of all open IBrowserContext. In a newly created browser, this will return a single instance of IBrowserContext.
public override IBrowserContext[] BrowserContexts()
Returns
- IBrowserContext[]
An array of IBrowserContext objects.
CloseAsync()
Closes Chromium and all of its pages (if any were opened). The browser object itself is considered disposed and cannot be used anymore.
public override Task CloseAsync()
Returns
- Task
Task.
CreateBrowserContextAsync(BrowserContextOptions)
Creates a new browser context. This won't share cookies/cache with other browser contexts.
public override Task<IBrowserContext> CreateBrowserContextAsync(BrowserContextOptions options = null)
Parameters
optionsBrowserContextOptionsOptions.
Returns
- Task<IBrowserContext>
Task which resolves to a new IBrowserContext object.
Examples
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()
Disconnects Puppeteer from the browser, but leaves the process running. After calling Disconnect(), the browser object is considered disposed and cannot be used anymore.
public override void Disconnect()
ExtensionsAsync()
Returns a map of installed extensions, keyed by extension ID.
public override Task<IReadOnlyDictionary<string, Extension>> ExtensionsAsync()
Returns
- Task<IReadOnlyDictionary<string, Extension>>
A task that resolves to a dictionary of extension ID to Extension.
GetPWAStateAsync(GetPWAStateOptions)
Returns the OS-integration state of an installed Progressive Web App (PWA), such as its badge count and registered file handlers.
public override Task<PWAState> GetPWAStateAsync(GetPWAStateOptions options)
Parameters
optionsGetPWAStateOptionsOptions for querying the PWA state.
Returns
Remarks
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()
Gets the browser's original user agent.
public override Task<string> GetUserAgentAsync()
Returns
Remarks
Pages can override browser user agent with SetUserAgentAsync(string, UserAgentMetadata).
GetVersionAsync()
Gets the browser's version.
public override Task<string> GetVersionAsync()
Returns
- Task<string>
For headless Chromium, this is similar to
HeadlessChrome/61.0.3153.0. For non-headless, this is similar toChrome/61.0.3153.0.
Remarks
the format of GetVersionAsync() might change with future releases of Chromium.
GetWindowBoundsAsync(string)
Gets the specified window bounds.
public override Task<WindowBounds> GetWindowBoundsAsync(string windowId)
Parameters
windowIdstringThe window ID.
Returns
- Task<WindowBounds>
A task that resolves to the WindowBounds.
InstallExtensionAsync(string, ExtensionInstallOptions)
Installs an unpacked extension and returns the extension ID.
public override Task<string> InstallExtensionAsync(string path, ExtensionInstallOptions options = null)
Parameters
pathstringThe path to the unpacked extension directory.
optionsExtensionInstallOptionsOptions for installing the extension.
Returns
InstallPWAAsync(InstallPWAOptions)
Installs a Progressive Web App (PWA) and returns its manifest id.
public override Task<string> InstallPWAAsync(InstallPWAOptions options)
Parameters
optionsInstallPWAOptionsOptions for installing the PWA.
Returns
Remarks
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)
Launches an installed Progressive Web App (PWA) and resolves with the IPage backing the app window.
public override Task<IPage> LaunchPWAAsync(LaunchPWAOptions options)
Parameters
optionsLaunchPWAOptionsOptions for launching the PWA.
Returns
Remarks
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)
Creates a new page.
public override Task<IPage> NewPageAsync(CreatePageOptions options = null)
Parameters
optionsCreatePageOptionsOptions for creating the page.
Returns
RemoveScreenAsync(string)
Removes the screen associated with the given screen ID, unless it is the primary screen.
public override Task RemoveScreenAsync(string screenId)
Parameters
screenIdstringThe ID of the screen to remove.
Returns
- Task
A task that completes when the screen is removed.
Remarks
Only supported in headless mode. Fails if the primary screen ID is specified.
ScreensAsync()
Gets a list of ScreenInfo objects.
public override Task<ScreenInfo[]> ScreensAsync()
Returns
- Task<ScreenInfo[]>
A task that resolves to an array of screen information objects.
SetWindowBoundsAsync(string, WindowBounds)
Sets the specified window bounds.
public override Task SetWindowBoundsAsync(string windowId, WindowBounds windowBounds)
Parameters
windowIdstringThe window ID.
windowBoundsWindowBoundsThe bounds to set.
Returns
- Task
A task that resolves when the bounds have been set.
Targets()
Returns An Array of all active targets.
public override ITarget[] Targets()
Returns
- ITarget[]
An Array of all active targets.
UninstallExtensionAsync(string)
Uninstalls a previously installed extension by its ID.
public override Task UninstallExtensionAsync(string id)
Parameters
idstringThe extension ID to uninstall.
Returns
- Task
A task that completes when the extension is uninstalled.
UninstallPWAAsync(UninstallPWAOptions)
Uninstalls a previously installed Progressive Web App (PWA).
public override Task UninstallPWAAsync(UninstallPWAOptions options)
Parameters
optionsUninstallPWAOptionsOptions for uninstalling the PWA.
Returns
- Task
A task that completes when the PWA is uninstalled.
Remarks
Only available over a pipe connection. See InstallPWAAsync(InstallPWAOptions).