Interface ICDPSession
- Namespace
- PuppeteerSharp
- Assembly
- PuppeteerSharp.dll
The CDPSession instances are used to talk raw Chrome Devtools Protocol:
- Protocol methods can be called with SendAsync(string, object, bool, CommandOptions) method.
- Protocol events, using the MessageReceived event.
Documentation on DevTools Protocol can be found here: https://chromedevtools.github.io/devtools-protocol/.
var client = await Page.Target.CreateCDPSessionAsync();
await client.SendAsync("Animation.enable");
client.MessageReceived += (sender, e) =>
{
if (e.MessageID == "Animation.animationCreated")
{
Console.WriteLine("Animation created!");
}
};
JObject response = await client.SendAsync("Animation.getPlaybackRate");
Console.WriteLine("playback rate is " + response.playbackRate);
await client.SendAsync("Animation.setPlaybackRate", new
{
playbackRate = Convert.ToInt32(response.playbackRate / 2)
});
public interface ICDPSession : ICDPConnection
Properties
CloseReason
Close reason if the session has been closed.
string CloseReason { get; }
Property Value
Id
Gets the session identifier.
string Id { get; }
Property Value
- string
The session identifier.
LoggerFactory
Gets the logger factory.
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.
Task DetachAsync()
Returns
- Task
A Task that when awaited detaches from the session target.
Exceptions
- PuppeteerException
If the Connection is closed.
Events
Disconnected
Occurs when the connection is closed.
event EventHandler Disconnected
Event Type
SessionAttached
Occurs when the session is attached to the target.
event EventHandler<SessionEventArgs> SessionAttached
Event Type
SessionDetached
Occurs when the session is detached from the target.
event EventHandler<SessionEventArgs> SessionDetached