|
|
|
"use strict";(self.webpackChunkwebsite=self.webpackChunkwebsite||[]).push([[27065],{51923:(e,r,s)=>{s.r(r),s.d(r,{assets:()=>d,contentTitle:()=>p,default:()=>h,frontMatter:()=>i,metadata:()=>c,toc:()=>o});var t=s(85893),n=s(11151);const i={sidebar_label:"Browser"},p="Browser class",c={id:"api/puppeteer.browser",title:"Browser class",description:"Browser represents a browser instance that is either:",source:"@site/versioned_docs/version-22.10.1/api/puppeteer.browser.md",sourceDirName:"api",slug:"/api/puppeteer.browser",permalink:"/api/puppeteer.browser",draft:!1,unlisted:!1,tags:[],version:"22.10.1",frontMatter:{sidebar_label:"Browser"},sidebar:"api",previous:{title:"Puppeteer.unregisterCustomQueryHandler",permalink:"/api/puppeteer.puppeteer.unregistercustomqueryhandler"},next:{title:"Browser.browserContexts",permalink:"/api/puppeteer.browser.browsercontexts"}},d={},o=[{value:"Signature:",id:"signature",level:4},{value:"Remarks",id:"remarks",level:2},{value:"Example 1",id:"example-1",level:2},{value:"Example 2",id:"example-2",level:2},{value:"Properties",id:"properties",level:2},{value:"Methods",id:"methods",level:2}];function a(e){const r={a:"a",code:"code",em:"em",h1:"h1",h2:"h2",h4:"h4",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:"browser-class",children:"Browser class"}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/api/puppeteer.browser",children:"Browser"})," represents a browser instance that is either:"]}),"\n",(0,t.jsxs)(r.ul,{children:["\n",(0,t.jsxs)(r.li,{children:["connected to via ",(0,t.jsx)(r.a,{href:"/api/puppeteer.puppeteer.connect",children:"Puppeteer.connect()"})," or - launched by ",(0,t.jsx)(r.a,{href:"/api/puppeteer.puppeteernode.launch",children:"PuppeteerNode.launch()"}),"."]}),"\n"]}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.a,{href:"/api/puppeteer.browser",children:"Browser"})," ",(0,t.jsx)(r.a,{href:"/api/puppeteer.eventemitter.emit",children:"emits"})," various events which are documented in the ",(0,t.jsx)(r.a,{href:"/api/puppeteer.browserevent",children:"BrowserEvent"})," enum."]}),"\n",(0,t.jsx)(r.h4,{id:"signature",children:"Signature:"}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-typescript",children:"export declare abstract class Browser extends EventEmitter<BrowserEvents>\n"})}),"\n",(0,t.jsxs)(r.p,{children:[(0,t.jsx)(r.strong,{children:"Extends:"})," ",(0,t.jsx)(r.a,{href:"/api/puppeteer.eventemitter",children:"EventEmitter"}),"<",(0,t.jsx)(r.a,{href:"/api/puppeteer.browserevents",children:"BrowserEvents"}),">"]}),"\n",(0,t.jsx)(r.h2,{id:"remarks",children:"Remarks"}),"\n",(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."]}),"\n",(0,t.jsx)(r.h2,{id:"example-1",children:"Example 1"}),"\n",(0,t.jsxs)(r.p,{children:["Using a ",(0,t.jsx)(r.a,{href:"/api/puppeteer.browser",children:"Browser"})," to create a ",(0,t.jsx)(r.a,{href:"/api/puppeteer.page",children:"Page"}),":"]}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\nconst browser = await puppeteer.launch();\nconst page = await browser.newPage();\nawait page.goto('https://example.com');\nawait browser.close();\n"})}),"\n",(0,t.jsx)(r.h2,{id:"example-2",children:"Example 2"}),"\n",(0,t.jsxs)(r.p,{children:["Disconnecting from and reconnecting to a ",(0,t.jsx)(r.a,{href:"/api/puppeteer.browser",children:"Browser"}),":"]}),"\n",(0,t.jsx)(r.pre,{children:(0,t.jsx)(r.code,{className:"language-ts",children:"import puppeteer from 'puppeteer';\n\nconst browser = await puppeteer.launch();\n// Store the endpoint to be able to reconnect to the browser.\nconst browserWSEndpoint = browser.wsEndpoint();\n// Disconnect puppeteer from the browser.\nawait browser.disconnect();\n\n// Use the endpoint to reestablish a connection\nconst browser2 = await puppeteer.connect({browserWSEn
|