跳至主要内容

CDPSession

CDPSession 实例用于直接与 Chrome Devtools 协议通信:

  • 协议方法可以通过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
});

方法

detach

Added before v1.9 cdpSession.detach

将CDPSession从目标分离。一旦分离,CDPSession对象将不再发出任何事件,也无法用于发送消息。

用法

await cdpSession.detach();

返回


发送

Added before v1.9 cdpSession.send

用法

await cdpSession.send(method);
await cdpSession.send(method, params);

参数

  • method string#

    协议方法名称。

  • params Object (可选)#

    可选的方法参数。

返回