Skip to content

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:

python
client = await page.context.new_cdp_session(page)
await client.send("Animation.enable")
client.on("Animation.animationCreated", lambda: print("animation created!"))
response = await client.send("Animation.getPlaybackRate")
print("playback rate is " + str(response["playbackRate"]))
await client.send("Animation.setPlaybackRate", {
    "playbackRate": response["playbackRate"] / 2
})
python
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 ​

cdp_session.detach() ​

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.

cdp_session.send() ​

Added in: v1.8

Arguments

  • method string

    Protocol method name.

  • params Object (optional)

    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

  • Object

Events ​

cdpSession.on("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

Released under the Apache 2.0 License.