Table of Contents

Class Connection

Namespace
PuppeteerSharp.Cdp
Assembly
PuppeteerSharp.dll

A connection handles the communication with a Chromium browser.

public sealed class Connection : IDisposable, ICDPConnection
Inheritance
Connection
Implements

Properties

CloseReason

Connection close reason.

public string CloseReason { get; }

Property Value

string

Delay

Gets the sleep time when a message is received.

public int Delay { get; }

Property Value

int

The delay.

IsClosed

Gets a value indicating whether this Connection is closed.

public bool IsClosed { get; }

Property Value

bool

true if is closed; otherwise, false.

LoggerFactory

Gets the logger factory.

public ILoggerFactory LoggerFactory { get; }

Property Value

ILoggerFactory

The logger factory.

Transport

Gets the Connection transport.

public IConnectionTransport Transport { get; }

Property Value

IConnectionTransport

Connection transport.

Url

Gets the WebSocket URL.

public string Url { get; }

Property Value

string

The URL.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

SendAsync(string, object, bool, CommandOptions)

Protocol methods can be called with this method.

public Task<JObject> SendAsync(string method, object args = null, bool waitForCallback = true, CommandOptions options = null)

Parameters

method string

The method name.

args object

The method args.

waitForCallback bool

If true the method will return a task to be completed when the message is confirmed by Chromium. If false the task will be considered complete after sending the message to Chromium.

options CommandOptions

The options.

Returns

Task<JObject>

The task.

Exceptions

PuppeteerException

If the Connection is closed.

SendAsync<T>(string, object, CommandOptions)

Protocol methods can be called with this method.

public Task<T> SendAsync<T>(string method, object args = null, CommandOptions options = null)

Parameters

method string

The method name.

args object

The method args.

options CommandOptions

The options.

Returns

Task<T>

The task.

Type Parameters

T

Return type.

Events

Disconnected

Occurs when the connection is closed.

public event EventHandler Disconnected

Event Type

EventHandler

MessageReceived

Occurs when a message from chromium is received.

public event EventHandler<MessageEventArgs> MessageReceived

Event Type

EventHandler<MessageEventArgs>