CDPSession
Namespace: PuppeteerSharp
public abstract class CDPSession : ICDPSession, ICDPConnectionSupports 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
Properties
Section titled “Properties”CloseReason
Section titled “CloseReason”public string CloseReason { get; protected set; }Close reason if the session has been closed.
Value: string
Detached
Section titled “Detached”public abstract bool Detached { get; }True if the session has been detached, false otherwise.
Value: bool
public string Id { get; init; }Gets the session identifier.
Value: string — The session identifier.
LoggerFactory
Section titled “LoggerFactory”public virtual ILoggerFactory LoggerFactory { get; }Gets the logger factory.
Value: ILoggerFactory — The logger factory.
Events
Section titled “Events”Disconnected
Section titled “Disconnected”public event EventHandler DisconnectedOccurs when the connection is closed.
Value: EventHandler
MessageReceived
Section titled “MessageReceived”public event EventHandler<MessageEventArgs> MessageReceivedOccurs when message received from Chromium.
Value: EventHandler<MessageEventArgs>
SessionAttached
Section titled “SessionAttached”public event EventHandler<SessionEventArgs> SessionAttachedOccurs when the session is attached to the target.
Value: EventHandler<SessionEventArgs>
SessionDetached
Section titled “SessionDetached”public event EventHandler<SessionEventArgs> SessionDetachedOccurs when the session is detached from the target.
Value: EventHandler<SessionEventArgs>
Methods
Section titled “Methods”Close(string)
Section titled “Close(string)”public abstract void Close(string closeReason)Closes the session.
Parameters
| Name | Type | Description |
|---|---|---|
closeReason |
string | The close reason. |
DetachAsync()
Section titled “DetachAsync()”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. |
OnDisconnected()
Section titled “OnDisconnected()”protected void OnDisconnected()Emits Disconnected event.
OnMessageReceived(MessageEventArgs)
Section titled “OnMessageReceived(MessageEventArgs)”protected void OnMessageReceived(MessageEventArgs e)Emits MessageReceived event.
Parameters
| Name | Type | Description |
|---|---|---|
e |
MessageEventArgs | Event arguments. |
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. |
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.
Made with love by Dario Kondratiuk