跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

CDPSession ​

Added in: v1.8

The CDPSession instances are used to talk raw Chrome Devtools Protocol:

  • protocol methods can be called with session.send method.
  • protocol events can be subscribed to with session.on method.

Useful links:

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.8

Detaches 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.30

Returns an event emitter for the given CDP event name.

Arguments

  • eventName string

    CDP event name.

Returns

  • CDPSessionEvent

CdpSession.SendAsync() ​

Added in: v1.8

Arguments

  • method string

    Protocol method name.

  • args Map<string, Object> (optional) Added in: v1.30

    Optional method parameters.

  • options Object (optional)

    • timeout float (optional) Added in: v1.65

      Maximum time in milliseconds to wait for the response. Defaults to 0 - no timeout.

Returns

  • JsonElement?

Events ​

CdpSession.Close ​

Added in: v1.59

Emitted when the session is closed, either because the target was closed or session.detach() was called.

Event data

  • CDPSession

基于 Apache 2.0 许可证发布。