Skip to main content

CDPSession

CDPSession 实例用于与原始 Chrome 开发者工具协议进行通信:

  • 可以使用 session.send 方法调用协议方法。
  • 可以使用 session.on 方法订阅协议事件。

有用的链接:

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 对象将不会发出任何事件,也不能用于发送消息。

cdpSession.send(method[, params])

Added in: v1.8