CDPSession 类
CDPSession 实例用于直接与 Chrome Devtools 协议通信。
签名
export declare abstract class CDPSession extends EventEmitter<CDPSessionEvents>
继承自: EventEmitter<CDPSessionEvents>
备注
可以使用 CDPSession.send() 方法调用协议方法,可以使用 CDPSession.on 方法订阅协议事件。
有用的链接:DevTools 协议查看器 和 DevTools 协议入门。
此类的构造函数被标记为内部的。第三方代码不应直接调用构造函数或创建扩展 CDPSession 类的子类。
示例
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,
});
方法
方法 | 修饰符 | 描述 |
|---|---|---|
| connection() | ||
| detach() | 将 cdpSession 从目标分离。分离后,cdpSession 对象将不会发出任何事件,并且不能用于发送消息。 | |
| id() | 返回会话的 ID。 | |
| send(method, params, options) |