Class BidiBrowser
- Namespace
- PuppeteerSharp.Bidi
- Assembly
- PuppeteerSharp.dll
Represents a browser connected using the Bidi protocol.
public class BidiBrowser : Browser, IBrowser, IDisposable, IAsyncDisposable
- Inheritance
-
BidiBrowser
- Implements
Properties
DefaultContext
Returns the default browser context. The default browser context can not be closed.
public override IBrowserContext DefaultContext { get; }
Property Value
- IBrowserContext
The default context.
IsClosed
Gets a value indicating if the browser is closed.
public override bool IsClosed { get; }
Property Value
IsConnected
Indicates that the browser is connected.
public override bool IsConnected { get; }
Property Value
Target
A target associated with the browser.
public override ITarget Target { get; }
Property Value
WebSocketEndpoint
Gets the Browser websocket url.
public override string WebSocketEndpoint { get; }
Property Value
Remarks
Browser websocket endpoint which can be used as an argument to ConnectAsync(ConnectOptions, 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 https://chromedevtools.github.io/devtools-protocol
and the browser endpoint https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target.
Methods
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()
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.
NewPageAsync()
Creates a new page.
public override Task<IPage> NewPageAsync()
Returns
Targets()
Returns An Array of all active targets.
public override ITarget[] Targets()
Returns
- ITarget[]
An Array of all active targets.