🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# class:cdpsession ### class: CDPSession v0.9.0 - extends: [`EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) `CDPSession` 实例用于与 Chrome Devtools 协议的原生通信: - 协议方法可以用 `session.send` 方法调用。 - 协议事件可以通过 `session.on` 方法订阅。 DevTools Protocol 的文档具体见这里: [DevTools Protocol Viewer](https://chromedevtools.github.io/devtools-protocol/). ``` const client = await page.target().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 - [cdpSession.detach()](#?product=Puppeteer&version=v1.11.0&show=api-cdpsessiondetach)v0.9.0 - [cdpSession.send(method\[, params\])](#?product=Puppeteer&version=v1.11.0&show=api-cdpsessionsendmethod-params)v0.9.0 ### Methods #### cdpSession.detach()v0.9.0 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> 从目标中分离 cdpSession。 一旦分离,cdpSession 对象将不会触发任何事件并且不能用于发送消息。 #### cdpSession.send(method\[, params\])v0.9.0 - `method` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> protocol method name - `params` <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> Optional method parameters - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> ![](images/pptr.png) puppeteer.js中文网|class:cdpsession puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档 puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。