1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["5348"],{33454(e,s,n){n.r(s),n.d(s,{metadata:()=>i,default:()=>h,frontMatter:()=>c,contentTitle:()=>r,toc:()=>d,assets:()=>o});var i=JSON.parse('{"id":"api/class-cdpsession","title":"CDPSession","description":"The CDPSession instances are used to talk raw Chrome Devtools Protocol:","source":"@site/docs/api/class-cdpsession.mdx","sourceDirName":"api","slug":"/api/class-cdpsession","permalink":"/docs/next/api/class-cdpsession","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"id":"class-cdpsession","title":"CDPSession"},"sidebar":"api","previous":{"title":"BrowserType","permalink":"/docs/next/api/class-browsertype"},"next":{"title":"Clock","permalink":"/docs/next/api/class-clock"}}'),t=n(74848),l=n(28453);n(13554),n(41647),n(83137);let c={id:"class-cdpsession",title:"CDPSession"},r,o={},d=[{value:"Methods",id:"methods",level:2},{value:"detach",id:"cdp-session-detach",level:3},{value:"send",id:"cdp-session-send",level:3},{value:"Events",id:"events",level:2},{value:"on('close')",id:"cdp-session-event-close",level:3},{value:"on('event')",id:"cdp-session-event-event",level:3}];function a(e){let s={a:"a",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,l.R)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(s.p,{children:["The ",(0,t.jsx)(s.code,{children:"CDPSession"})," instances are used to talk raw Chrome Devtools Protocol:"]}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["protocol methods can be called with ",(0,t.jsx)(s.code,{children:"session.send"})," method."]}),"\n",(0,t.jsxs)(s.li,{children:["protocol events can be subscribed to with ",(0,t.jsx)(s.code,{children:"session.on"})," method."]}),"\n"]}),"\n",(0,t.jsx)(s.p,{children:"Useful links:"}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["Documentation on DevTools Protocol can be found here: ",(0,t.jsx)(s.a,{href:"https://chromedevtools.github.io/devtools-protocol/",children:"DevTools Protocol Viewer"}),"."]}),"\n",(0,t.jsxs)(s.li,{children:["Getting Started with DevTools Protocol: ",(0,t.jsx)(s.a,{href:"https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md",children:"https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md"})]}),"\n"]}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"const client = await page.context().newCDPSession(page);\nawait client.send('Animation.enable');\nclient.on('Animation.animationCreated', () => console.log('Animation created!'));\nconst response = await client.send('Animation.getPlaybackRate');\nconsole.log('playback rate is ' + response.playbackRate);\nawait client.send('Animation.setPlaybackRate', {\n playbackRate: response.playbackRate / 2\n});\n"})}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h2,{id:"methods",children:"Methods"}),"\n",(0,t.jsx)(s.h3,{id:"cdp-session-detach",children:"detach"}),"\n",(0,t.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,t.jsx)("x-search",{children:"cdpSession.detach"}),"\n",(0,t.jsx)(s.p,{children:"Detaches the CDPSession from the target. Once detached, the CDPSession object won't emit any events and can't be used to send messages."}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Usage"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"await cdpSession.detach();\n"})}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined",title:"void",children:"void"}),">",(0,t.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"cdp-session-detach-return"}),(0,t.jsx)("a",{href:"#cdp-session-detach-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"cdp-session-send",children:"send"}),"\n",(0,t.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added before v1.9"}),"\n",(0,t.jsx)("x-search",{children:"cdpSession.send"}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Usage"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"await cdpSession.send(method
1);\nawait cdpSession.send(method, params);\n"})}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Arguments"})}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"method"})," ",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"}),(0,t.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"cdp-session-send-option-method"}),(0,t.jsx)("a",{href:"#cdp-session-send-option-method",class:"list-anchor",children:"#"})]}),"\n",(0,t.jsx)(s.p,{children:"Protocol method name."}),"\n"]}),"\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"params"})," ",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,t.jsx)(s.em,{children:"(optional)"}),(0,t.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"cdp-session-send-option-params"}),(0,t.jsx)("a",{href:"#cdp-session-send-option-params",class:"list-anchor",children:"#"})]}),"\n",(0,t.jsx)(s.p,{children:"Optional method parameters."}),"\n"]}),"\n"]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Returns"})}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",title:"Promise",children:"Promise"}),"<",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),">",(0,t.jsx)("a",{"aria-hidden":"true",tabIndex:"-1",class:"list-anchor-link",id:"cdp-session-send-return"}),(0,t.jsx)("a",{href:"#cdp-session-send-return",class:"list-anchor",children:"#"})]}),"\n"]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h2,{id:"events",children:"Events"}),"\n",(0,t.jsx)(s.h3,{id:"cdp-session-event-close",children:"on('close')"}),"\n",(0,t.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.59"}),"\n",(0,t.jsx)("x-search",{children:"cdpSession.on('close')"}),"\n",(0,t.jsxs)(s.p,{children:["Emitted when the session is closed, either because the target was closed or ",(0,t.jsx)(s.code,{children:"session.detach()"})," was called."]}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Usage"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"cdpSession.on('close', data => {});\n"})}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Event data"})}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsx)(s.li,{children:(0,t.jsx)(s.a,{href:"/docs/next/api/class-cdpsession",title:"CDPSession",children:"CDPSession"})}),"\n"]}),"\n",(0,t.jsx)(s.hr,{}),"\n",(0,t.jsx)(s.h3,{id:"cdp-session-event-event",children:"on('event')"}),"\n",(0,t.jsx)("font",{size:"2",style:{position:"relative",top:"-20px"},children:"Added in: v1.59"}),"\n",(0,t.jsx)("x-search",{children:"cdpSession.on('event')"}),"\n",(0,t.jsx)(s.p,{children:"Emitted for every CDP event received from the session. Allows subscribing to all CDP events at once without knowing their names ahead of time."}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Usage"})}),"\n",(0,t.jsx)(s.pre,{children:(0,t.jsx)(s.code,{className:"language-js",children:"session.on('event', ({ method, params }) => {\n console.log(`CDP event: ${method}`, params);\n});\n"})}),"\n",(0,t.jsx)(s.p,{children:(0,t.jsx)(s.strong,{children:"Event data"})}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:[(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"}),"\n",(0,t.jsxs)(s.ul,{children:["\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"method"})," ",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type",title:"string",children:"string"})]}),"\n",(0,t.jsx)(s.p,{children:"CDP event name."}),"\n"]}),"\n",(0,t.jsxs)(s.li,{children:["\n",(0,t.jsxs)(s.p,{children:[(0,t.jsx)(s.code,{children:"params"})," ",(0,t.jsx)(s.a,{href:"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object",title:"Object",children:"Object"})," ",(0,t.jsx)(s.em,{children:"(optional)"})]}),"\n",(0,t.jsx)(s.p,{children:"CDP event parameters."}),"\n"]}),"\n"]}),"\n"]}),"\n"]})]})}function h(e={}){let{wrapper:s}={...(0,l.R)(),...e.components};return s?(0,t.jsx)(s,{...e,children:(0,t.jsx)(a,{...e})}):a(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.