Skip to content

CDPSession

Namespace: PuppeteerSharp

public abstract class CDPSession : ICDPSession, ICDPConnection

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.

Inheritance: object

Implements: ICDPSession, ICDPConnection

Derived: BidiCdpSession, CdpCDPSession

View source

public string CloseReason { get; protected set; }

Close reason if the session has been closed.

Value: string

View source

public abstract bool Detached { get; }

True if the session has been detached, false otherwise.

Value: bool

View source

public string Id { get; init; }

Gets the session identifier.

Value: string — The session identifier.

View source

public virtual ILoggerFactory LoggerFactory { get; }

Gets the logger factory.

Value: ILoggerFactory — The logger factory.

View source

public event EventHandler Disconnected

Occurs when the connection is closed.

Value: EventHandler

View source

public event EventHandler<MessageEventArgs> MessageReceived

Occurs when message received from Chromium.

Value: EventHandler<MessageEventArgs>

View source

public event EventHandler<SessionEventArgs> SessionAttached

Occurs when the session is attached to the target.

Value: EventHandler<SessionEventArgs>

View source

public event EventHandler<SessionEventArgs> SessionDetached

Occurs when the session is detached from the target.

Value: EventHandler<SessionEventArgs>

View source

public abstract void Close(string closeReason)

Closes the session.

Parameters

Name Type Description
closeReason string The close reason.

View source

public abstract Task DetachAsync()

Detaches session from target. Once detached, session won’t emit any events and can’t be used to send messages.

Returns: Task — A Task that when awaited detaches from the session target.

Exceptions

Type Condition
PuppeteerException If the Connection is closed.

View source

protected void OnDisconnected()

Emits Disconnected event.

View source

protected void OnMessageReceived(MessageEventArgs e)

Emits MessageReceived event.

Parameters

Name Type Description
e MessageEventArgs Event arguments.

View source

SendAsync(string, object, bool, CommandOptions)

Section titled “SendAsync(string, object, bool, CommandOptions)”
public abstract Task<JsonElement?> SendAsync(string method, object args = null, bool waitForCallback = true, CommandOptions options = null)

Protocol methods can be called with this method.

Parameters

Name Type Description
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<JsonElement?> — The task.

Exceptions

Type Condition
PuppeteerException If the Connection is closed.

View source

SendAsync<T>(string, object, CommandOptions)

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

Protocol methods can be called with this method.

Type parameters

Name Description
T Return type.

Parameters

Name Type Description
method string The method name.
args object The method args.
options CommandOptions The options.

Returns: Task<T> — The task.

View source

Made with love by Dario Kondratiuk