Class CDPSession
- Namespace
- PuppeteerSharp
- 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 abstract class CDPSession : ICDPSession, ICDPConnection
- Inheritance
-
CDPSession
- Implements
- Derived
Properties
CloseReason
Close reason if the session has been closed.
public string CloseReason { get; protected set; }
Property Value
Id
Gets the session identifier.
public string Id { get; init; }
Property Value
- string
The session identifier.
LoggerFactory
Gets the logger factory.
public ILoggerFactory LoggerFactory { get; }
Property Value
- ILoggerFactory
The logger factory.
Methods
DetachAsync()
Detaches session from target. Once detached, session won't emit any events and can't be used to send messages.
public abstract Task DetachAsync()
Returns
- Task
A Task that when awaited detaches from the session target.
Exceptions
- PuppeteerException
If the Connection is closed.
OnDisconnected()
Emits Disconnected event.
protected void OnDisconnected()
OnMessageReceived(MessageEventArgs)
Emits MessageReceived event.
protected void OnMessageReceived(MessageEventArgs e)
Parameters
e
MessageEventArgsEvent arguments.
SendAsync(string, object, bool, CommandOptions)
Protocol methods can be called with this method.
public abstract Task<JsonElement?> SendAsync(string method, object args = null, bool waitForCallback = true, CommandOptions options = null)
Parameters
method
stringThe method name.
args
objectThe method args.
waitForCallback
boolIf
true
the method will return a task to be completed when the message is confirmed by Chromium. Iffalse
the task will be considered complete after sending the message to Chromium.options
CommandOptionsThe options.
Returns
- Task<JsonElement?>
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
stringThe method name.
args
objectThe method args.
options
CommandOptionsThe 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
MessageReceived
Occurs when message received from Chromium.
public event EventHandler<MessageEventArgs> MessageReceived
Event Type
SessionAttached
Occurs when the session is attached to the target.
public event EventHandler<SessionEventArgs> SessionAttached
Event Type
SessionDetached
Occurs when the session is detached from the target.
public event EventHandler<SessionEventArgs> SessionDetached