CDPSession
Added in: v1.8The CDPSession instances are used to talk raw Chrome Devtools Protocol:
- protocol methods can be called with
session.sendmethod. - protocol events can be subscribed to with
session.onmethod.
Useful links:
- Documentation on DevTools Protocol can be found here: DevTools Protocol Viewer.
- Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
csharp
var client = await Page.Context.NewCDPSessionAsync(Page);
await client.SendAsync("Runtime.enable");
client.Event("Animation.animationCreated").OnEvent += (_, _) => Console.WriteLine("Animation created!");
var response = await client.SendAsync("Animation.getPlaybackRate");
var playbackRate = response.Value.GetProperty("playbackRate").GetDouble();
Console.WriteLine("playback rate is " + playbackRate);
await client.SendAsync("Animation.setPlaybackRate", new() { { "playbackRate", playbackRate / 2 } });Methods
CdpSession.DetachAsync()
Added in: v1.8Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to send messages.
CdpSession.Event()
Added in: v1.30Returns an event emitter for the given CDP event name.
Arguments
Returns
CDPSessionEvent
CdpSession.SendAsync()
Added in: v1.8Arguments
Returns
JsonElement?
Events
CdpSession.Close
Added in: v1.59Emitted when the session is closed, either because the target was closed or session.detach() was called.
Event data
CDPSession