CDPSession
CDPSession
實例用於與原始 Chrome Devtools Protocol 通訊
- 協定方法可以使用
session.send
方法調用。 - 協定事件可以使用
session.on
方法訂閱。
實用連結
- DevTools Protocol 的文件可以在這裡找到:DevTools Protocol Viewer。
- DevTools Protocol 入門:https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
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 } });
方法
DetachAsync
在 v1.9 之前新增將 CDPSession 從目標分離。一旦分離,CDPSession 物件將不會發出任何事件,且不能用於發送訊息。
用法
await CdpSession.DetachAsync();
回傳
事件
在 v.1.30 中新增傳回給定 CDP 事件名稱的事件發射器。
用法
CdpSession.Event(eventName);
參數
回傳
SendAsync
在 v1.9 之前新增用法
await CdpSession.SendAsync(method, params);
參數
回傳
- [JsonElement?]#