CDPSession
Added in: v1.8The CDPSession instances are used to talk raw Chrome Devtools Protocol:
- protocol methods can be called with
session.sendmethod. - protocol events can be subscribed to with
session.onmethod.
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
cdpSession.detach()
Added in: v1.8 asyncDetaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to send messages.
cdpSession.send()
Added in: v1.8 asyncArguments
Protocol method name.
Optional method parameters.
signalAbortSignal(optional) Added in: v1.65Allows to cancel the operation using an
AbortSignal. If the signal is aborted, the operation will be aborted and throw an error.timeoutfloat(optional) Added in: v1.65Maximum time in milliseconds to wait for the response. Defaults to
0- no timeout.
Returns
Promise<Object>
Events
cdpSession.on('close')
Added in: v1.59Emitted when the session is closed, either because the target was closed or session.detach() was called.
Event data
CDPSession
cdpSession.on('event')
Added in: v1.59Emitted 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