CDPSession
- 继承自: EventEmitter
CDPSession 实例用于与原始 Chrome 开发者工具协议进行通信:
- 可以使用
session.send方法调用协议方法。 - 可以使用
session.on方法订阅协议事件。
有用的链接:
- DevTools 协议文档可以在这里找到:DevTools Protocol Viewer。
- DevTools 协议入门: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
});
cdpSession.detach()
Added in: v1.8将 CDPSession 从目标分离。一旦分离,CDPSession 对象将不会发出任何事件,也不能用于发送消息。