Skip to main content
Version: 22.9.0

CDPSession 类

¥CDPSession class

CDPSession 实例用于讨论原始 Chrome Devtools 协议。

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

签名:

¥Signature:

export declare abstract class CDPSession extends EventEmitter<CDPSessionEvents>

Extends: EventEmitter<CDPSessionEvents>

备注

¥Remarks

协议方法可以通过 CDPSession.send() 方法调用,协议事件可以通过 CDPSession.on 方法订阅。

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

有用的链接:DevTools 协议查看器DevTools 协议入门

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

此类的构造函数被标记为内部构造函数。第三方代码不应直接调用构造函数或创建扩展 CDPSession 类的子类。

¥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

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,
});

方法

¥Methods

方法

修饰符

描述

connection()
detach()

将 cdpSession 与目标分离。一旦分离,cdpSession 对象将不会触发任何事件,也不能用于发送消息。

id()

返回会话的 ID。

send(method, params, options)