Skip to main content

CDPSession

CDPSession 实例用于讨论原始 Chrome Devtools 协议:

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

  • 协议方法可以通过 session.send 方法调用。

    ¥protocol methods can be called with session.send method.

  • 可以使用 session.on 方法订阅协议事件。

    ¥protocol events can be subscribed to with session.on method.

有用的链接:

¥Useful links:

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
})

方法

¥Methods

detach

Added before v1.9 cdpSession.detach

从目标分离 CDPSession。一旦分离,CDPSession 对象将不会触发任何事件,也不能用于发送消息。

¥Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to send messages.

用法

¥Usage

cdp_session.detach()

返回

¥Returns


send

Added before v1.9 cdpSession.send

用法

¥Usage

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

参数

¥Arguments

协议方法名称。

¥Protocol method name.

  • params Dict (optional)#

可选方法参数。

¥Optional method parameters.

返回

¥Returns