GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Playwright for Python
  • Docs
  • API
  • Python
  • Node.js
  • Java
  • .NET
  • Community
  • Classes
  • APIRequestContext
  • APIResponse
  • Browser
  • BrowserContext
  • BrowserType

This view

  • Original page
  • New address

GeezerVison is showing playwright.dev — CDPSession | Playwright Python

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:

  • Documentation on DevTools Protocol can be found here: DevTools Protocol Viewer.
  • Getting Started with DevTools Protocol: https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
  • Sync
  • Async
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
})
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
})

Methods​

detach​

Added before v1.9 cdpSession.detach

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

  • NoneType#

send​

Added before v1.9 cdpSession.send

Usage

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

Arguments

  • method str#

    Protocol method name.

  • params Dict (optional)#

    Optional method parameters.

  • timeout float (optional) Added in: v1.65#

    Maximum time in milliseconds to wait for the response. Defaults to 0 - no timeout.

Returns

  • Dict#

Events​

on("close")​

Added in: v1.59 cdpSession.on("close")

Emitted when the session is closed, either because the target was closed or session.detach() was called.

Usage

cdp_session.on("close", handler)

Event data

  • CDPSession
  • Methods
    • detach
    • send
  • Events
    • on("close")
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.