2021-01-07 11:46:05 -08:00
|
|
|
# class: CDPSession
|
2021-02-01 11:13:13 -08:00
|
|
|
* langs: js, python
|
2021-01-14 15:01:39 -08:00
|
|
|
* extends: [EventEmitter]
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
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:
|
2021-01-14 07:48:56 -08:00
|
|
|
* Documentation on DevTools Protocol can be found here:
|
|
|
|
[DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/).
|
|
|
|
* Getting Started with DevTools Protocol:
|
|
|
|
https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md
|
2021-01-07 11:46:05 -08:00
|
|
|
|
|
|
|
```js
|
|
|
|
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
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2021-01-14 07:48:56 -08:00
|
|
|
```python async
|
|
|
|
client = await page.context().new_cdp_session(page)
|
2021-06-25 11:53:55 -07:00
|
|
|
await client.send("Animation.enable")
|
|
|
|
client.on("Animation.animationCreated", lambda: print("animation created!"))
|
|
|
|
response = await client.send("Animation.getPlaybackRate")
|
2021-06-26 08:30:06 -07:00
|
|
|
print("playback rate is " + str(response["playbackRate"]))
|
|
|
|
await client.send("Animation.setPlaybackRate", {
|
|
|
|
playbackRate: response["playbackRate"] / 2
|
2021-01-14 07:48:56 -08:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
|
|
|
```python sync
|
|
|
|
client = page.context().new_cdp_session(page)
|
2021-06-25 11:53:55 -07:00
|
|
|
client.send("Animation.enable")
|
|
|
|
client.on("Animation.animationCreated", lambda: print("animation created!"))
|
|
|
|
response = client.send("Animation.getPlaybackRate")
|
2021-06-26 08:30:06 -07:00
|
|
|
print("playback rate is " + str(response["playbackRate"]))
|
2021-06-25 11:53:55 -07:00
|
|
|
client.send("Animation.setPlaybackRate", {
|
2021-06-26 08:31:36 -07:00
|
|
|
playbackRate: response["playbackRate"] / 2
|
2021-01-14 07:48:56 -08:00
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2021-01-07 11:46:05 -08:00
|
|
|
## async method: 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.
|
|
|
|
|
|
|
|
## async method: CDPSession.send
|
|
|
|
- returns: <[Object]>
|
|
|
|
|
|
|
|
### param: CDPSession.send.method
|
|
|
|
- `method` <[string]>
|
|
|
|
|
|
|
|
protocol method name
|
|
|
|
|
|
|
|
### param: CDPSession.send.params
|
|
|
|
- `params` <[Object]>
|
|
|
|
|
|
|
|
Optional method parameters
|