跳到主要內容

CDPSession

CDPSession 實例用於與原始 Chrome Devtools Protocol 通訊

  • 協定方法可以使用 session.send 方法呼叫。
  • 協定事件可以使用 session.on 方法訂閱。

實用連結

client = page.context.new_cdp_session(page)
client.send("Animation.enable")
client.on("Animation.animationCreated", lambda: print("animation created!"))
response = client.send("Animation.getPlaybackRate")
print("playback rate is " + str(response["playbackRate"]))
client.send("Animation.setPlaybackRate", {
"playbackRate": response["playbackRate"] / 2
})

方法

detach

v1.9 之前版本新增 cdpSession.detach

從目標分離 CDPSession。一旦分離,CDPSession 物件將不會發出任何事件,且不能用於發送訊息。

用法

cdp_session.detach()

返回值


send

v1.9 之前版本新增 cdpSession.send

用法

cdp_session.send(method)
cdp_session.send(method, **kwargs)

引數

  • method str#

    協定方法名稱。

  • params Dict (選用)#

    選用方法參數。

返回值