Back to Puppeteer

CDPSession class

docs/api/puppeteer.cdpsession.md

19.2.22.4 KB
Original Source

CDPSession class

The CDPSession instances are used to talk raw Chrome Devtools Protocol.

Signature

typescript
export declare abstract class CDPSession extends EventEmitter<CDPSessionEvents>

Extends: EventEmitter<CDPSessionEvents>

Remarks

Protocol methods can be called with CDPSession.send() method and protocol events can be subscribed to with CDPSession.on method.

Useful links: DevTools Protocol Viewer and Getting Started with DevTools Protocol.

The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the CDPSession class.

Example

ts
const client = await page.createCDPSession();
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,
});

Properties

<table><thead><tr><th>

Property

</th><th>

Modifiers

</th><th>

Type

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

<span id="detached">detached</span>

</td><td>

readonly

</td><td>

boolean

</td><td>

True if the session has been detached, false otherwise.

</td></tr> </tbody></table>

Methods

<table><thead><tr><th>

Method

</th><th>

Modifiers

</th><th>

Description

</th></tr></thead> <tbody><tr><td>

<span id="connection">connection()</span>

</td><td> </td><td>

The underlying connection for this session, if any.

</td></tr> <tr><td>

<span id="detach">detach()</span>

</td><td> </td><td>

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

</td></tr> <tr><td>

<span id="id">id()</span>

</td><td> </td><td>

Returns the session's id.

</td></tr> <tr><td>

<span id="send">send(method, params, options)</span>

</td><td> </td><td> </td></tr> </tbody></table>