跳到主要内容

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 (可选)#

    可选方法参数。

返回值