Spec-Zone.ru › Playwright

CDPSession

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
const client = await page.context().newCDPSession(page);
await client.send('Animation.enable');
client.on('Animation.animationCreated', () => console.log('Animation created!'));
const response = await client.send('Animation.getPlaybackRate');
console.log('playback rate is ' + response.playbackRate);
await client.send('Animation.setPlaybackRate', {
  playbackRate: response.playbackRate / 2
});

Methods​

detach​

Added before v1.9

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

await cdpSession.detach();

Returns

  • Promise<void>

send​

Added before v1.9

Usage

await cdpSession.send(method);
await cdpSession.send(method, params);

Arguments

  • method string

    Protocol method name.

  • params Object (optional)

    Optional method parameters.

Returns

  • Promise<Object>

Events​

on('close')​

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

Usage

cdpSession.on('close', data => {});

Event data

  • CDPSession

on('event')​

Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing their names ahead of time.

Usage

session.on('event', ({ method, params }) => {
  console.log(`CDP event: ${method}`, params);
});

Event data

  • Object
    • method string

      CDP event name.

    • params Object (optional)

      CDP event parameters.

© 2026 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-cdpsession

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API