/*! For license information please see 728bf073.9a6326ff.js.LICENSE.txt */ "use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[89774],{69732:(e,r,s)=>{s.r(r),s.d(r,{assets:()=>a,contentTitle:()=>d,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>p});var t=s(85893),n=s(11151);const i={sidebar_label:"API"},d="API Reference",c={id:"api/index",title:"API Reference",description:"Classes",source:"@site/../docs/api/index.md",sourceDirName:"api",slug:"/api/",permalink:"/next/api/",draft:!1,unlisted:!1,tags:[],version:"current",frontMatter:{sidebar_label:"API"}},a={},p=[{value:"Classes",id:"classes",level:2},{value:"Enumerations",id:"enumerations",level:2},{value:"Functions",id:"functions",level:2},{value:"Interfaces",id:"interfaces",level:2},{value:"Namespaces",id:"namespaces",level:2},{value:"Variables",id:"variables",level:2},{value:"Type Aliases",id:"type-aliases",level:2}];function l(e){const r={a:"a",admonition:"admonition",code:"code",em:"em",h1:"h1",h2:"h2",li:"li",p:"p",pre:"pre",strong:"strong",ul:"ul",...(0,n.a)(),...e.components};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r.h1,{id:"api-reference",children:"API Reference"}),"\n",(0,t.jsx)(r.h2,{id:"classes",children:"Classes"}),"\n",(0,t.jsxs)("table",{children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{children:[(0,t.jsx)("th",{children:(0,t.jsx)(r.p,{children:"Class"})}),(0,t.jsx)("th",{children:(0,t.jsx)(r.p,{children:"Description"})})]})}),(0,t.jsxs)("tbody",{children:[(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"accessibility",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.accessibility",children:"Accessibility"})})}),(0,t.jsxs)("td",{children:[(0,t.jsxs)(r.p,{children:["The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as ",(0,t.jsx)(r.a,{href:"https://en.wikipedia.org/wiki/Screen_reader",children:"screen readers"})," or ",(0,t.jsx)(r.a,{href:"https://en.wikipedia.org/wiki/Switch_access",children:"switches"}),"."]}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsx)(r.p,{children:"Accessibility is a very platform-specific thing. On different platforms, there are different screen readers that might have wildly different output."}),(0,t.jsx)(r.p,{children:'Blink - Chrome\'s rendering engine - has a concept of "accessibility tree", which is then translated into different platform-specific APIs. Accessibility namespace gives users access to the Blink Accessibility Tree.'}),(0,t.jsx)(r.p,{children:'Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or by assistive technologies themselves. By default, Puppeteer tries to approximate this filtering, exposing only the "interesting" nodes of the tree.'}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"Accessibility"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"browser",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})})}),(0,t.jsxs)("td",{children:[(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})," represents a browser instance that is either:"]}),(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:["connected to via ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.puppeteer.connect",children:"Puppeteer.connect()"})," or - launched by ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.puppeteernode.launch",children:"PuppeteerNode.launch()"}),"."]}),"\n"]}),(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"Browser"})," ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.eventemitter.emit",children:"emits"})," various events which are documented in the ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browserevent",children:"BrowserEvent"})," enum."]}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"Browser"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"browsercontext",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"BrowserContext"})})}),(0,t.jsxs)("td",{children:[(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"BrowserContext"})," represents individual user contexts within a ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"}),"."]}),(0,t.jsxs)(r.p,{children:["When a ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser",children:"browser"})," is launched, it has a single ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"browser context"})," by default. Others can be created using ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browser.createbrowsercontext",children:"Browser.createBrowserContext()"}),". Each context has isolated storage (cookies/localStorage/etc.)"]}),(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browsercontext",children:"BrowserContext"})," ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.eventemitter",children:"emits"})," various events which are documented in the ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.browsercontextevent",children:"BrowserContextEvent"})," enum."]}),(0,t.jsxs)(r.p,{children:["If a ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"page"})," opens another ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"page"}),", e.g. using ",(0,t.jsx)(r.code,{children:"window.open"}),", the popup will belong to the parent ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page.browsercontext",children:"page's browser context"}),"."]}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"BrowserContext"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"cdpsession",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.cdpsession",children:"CDPSession"})})}),(0,t.jsxs)("td",{children:[(0,t.jsxs)(r.p,{children:["The ",(0,t.jsx)(r.code,{children:"CDPSession"})," instances are used to talk raw Chrome Devtools Protocol."]}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["Protocol methods can be called with ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.cdpsession.send",children:"CDPSession.send()"})," method and protocol events can be subscribed to with ",(0,t.jsx)(r.code,{children:"CDPSession.on"})," method."]}),(0,t.jsxs)(r.p,{children:["Useful links: ",(0,t.jsx)(r.a,{href:"https://chromedevtools.github.io/devtools-protocol/",children:"DevTools Protocol Viewer"})," and ",(0,t.jsx)(r.a,{href:"https://github.com/aslushnikov/getting-started-with-cdp/blob/HEAD/README.md",children:"Getting Started with DevTools Protocol"}),"."]}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"CDPSession"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"connection",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.connection",children:"Connection"})})}),(0,t.jsx)("td",{})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"consolemessage",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.consolemessage",children:"ConsoleMessage"})})}),(0,t.jsx)("td",{children:(0,t.jsx)(r.p,{children:"ConsoleMessage objects are dispatched by page via the 'console' event."})})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"coverage",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.coverage",children:"Coverage"})})}),(0,t.jsxs)("td",{children:[(0,t.jsx)(r.p,{children:"The Coverage class provides methods to gather information about parts of JavaScript and CSS that were used by the page."}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["To output coverage in a form consumable by ",(0,t.jsx)(r.a,{href:"https://github.com/istanbuljs",children:"Istanbul"}),", see ",(0,t.jsx)(r.a,{href:"https://github.com/istanbuljs/puppeteer-to-istanbul",children:"puppeteer-to-istanbul"}),"."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"csscoverage",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.csscoverage",children:"CSSCoverage"})})}),(0,t.jsx)("td",{})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"devicerequestprompt",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.devicerequestprompt",children:"DeviceRequestPrompt"})})}),(0,t.jsxs)("td",{children:[(0,t.jsx)(r.p,{children:"Device request prompts let you respond to the page requesting for a device through an API like WebBluetooth."}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.code,{children:"DeviceRequestPrompt"})," instances are returned via the ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page.waitfordeviceprompt",children:"Page.waitForDevicePrompt()"})," method."]}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"DeviceRequestPrompt"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"devicerequestpromptdevice",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.devicerequestpromptdevice",children:"DeviceRequestPromptDevice"})})}),(0,t.jsxs)("td",{children:[(0,t.jsx)(r.p,{children:"Device in a request prompt."}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"DeviceRequestPromptDevice"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"dialog",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.dialog",children:"Dialog"})})}),(0,t.jsxs)("td",{children:[(0,t.jsxs)(r.p,{children:["Dialog instances are dispatched by the ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page",children:"Page"})," via the ",(0,t.jsx)(r.code,{children:"dialog"})," event."]}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the ",(0,t.jsx)(r.code,{children:"Dialog"})," class."]})]})]}),(0,t.jsxs)("tr",{children:[(0,t.jsx)("td",{children:(0,t.jsx)("span",{id:"elementhandle",children:(0,t.jsx)(r.a,{href:"/next/api/puppeteer.elementhandle",children:"ElementHandle"})})}),(0,t.jsxs)("td",{children:[(0,t.jsx)(r.p,{children:"ElementHandle represents an in-page DOM element."}),(0,t.jsx)(r.p,{children:(0,t.jsx)(r.strong,{children:"Remarks:"})}),(0,t.jsxs)(r.p,{children:["ElementHandles can be created with the ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page._",children:"Page.$()"})," method."]}),(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\n(async () => {\n const browser = await puppeteer.launch();\n const page = await browser.newPage();\n await page.goto('https://example.com');\n const hrefElement = await page.$('a');\n await hrefElement.click();\n // ...\n})();\n"})}),(0,t.jsxs)(r.p,{children:["ElementHandle prevents the DOM element from being garbage-collected unless the handle is ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.jshandle.dispose",children:"disposed"}),". ElementHandles are auto-disposed when their origin frame gets navigated."]}),(0,t.jsxs)(r.p,{children:["ElementHandle instances can be used as arguments in ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page._eval",children:"Page.$eval()"})," and ",(0,t.jsx)(r.a,{href:"/next/api/puppeteer.page.evaluate",children:"Page.evaluate()"})," methods."]}),(0,t.jsxs)(r.p,{children:["If you're using TypeScript, ElementHandle takes a generic argument that denotes the type of element the handle is holding within. For example, if you have a handle to a ",(0,t.jsx)(r.code,{children:"