<titledata-rh="true">Browser class | Puppeteer</title><metadata-rh="true"name="viewport"content="width=device-width,initial-scale=1"><metadata-rh="true"name="twitter:card"content="summary_large_image"><metadata-rh="true"property="og:url"content="https://pptr.dev/next/api/puppeteer.browser"><metadata-rh="true"property="og:locale"content="en"><metadata-rh="true"name="docsearch:language"content="en"><metadata-rh="true"name="docsearch:counter"content="3"><metadata-rh="true"property="og:title"content="Browser class | Puppeteer"><metadata-rh="true"name="description"content="Browser represents a browser instance that is either:"><metadata-rh="true"property="og:description"content="Browser represents a browser instance that is either:"><linkdata-rh="true"rel="icon"href="/img/favicon.ico"><linkdata-rh="true"rel="canonical"href="https://pptr.dev/next/api/puppeteer.browser"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.browser"hreflang="en"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.browser"hreflang="x-default"><linkdata-rh="true"rel="preconnect"href="https://DVKY664LG7-dsn.algolia.net"crossorigin="anonymous"><linkrel="search"type="application/opensearchdescription+xml"title="Puppeteer"href="/opensearch.xml">
<p><ahref="/next/api/puppeteer.browser">Browser</a> represents a browser instance that is either:</p>
<ul>
<li>connected to via <ahref="/next/api/puppeteer.puppeteer.connect">Puppeteer.connect()</a> or - launched by <ahref="/next/api/puppeteer.puppeteernode.launch">PuppeteerNode.launch()</a>.</li>
<p><ahref="/next/api/puppeteer.browser">Browser</a><ahref="/next/api/puppeteer.eventemitter.emit">emits</a> various events which are documented in the <ahref="/next/api/puppeteer.browserevent">BrowserEvent</a> enum.</p>
<h4class="anchor anchorWithStickyNavbar_FNw8"id="signature">Signature:<ahref="#signature"class="hash-link"aria-label="Direct link to Signature:"title="Direct link to Signature:"></a></h4>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="remarks">Remarks<ahref="#remarks"class="hash-link"aria-label="Direct link to Remarks"title="Direct link to Remarks"></a></h2>
<p>The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the <code>Browser</code> class.</p>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="example-1">Example 1<ahref="#example-1"class="hash-link"aria-label="Direct link to Example 1"title="Direct link to Example 1"></a></h2>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="example-2">Example 2<ahref="#example-2"class="hash-link"aria-label="Direct link to Example 2"title="Direct link to Example 2"></a></h2>
<divclass="language-ts codeBlockContainer_aalF theme-code-block"style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><divclass="codeBlockContent_MHx8"><pretabindex="0"class="prism-code language-ts codeBlock_zHgq thin-scrollbar"style="color:#393A34;background-color:#f6f8fa"><codeclass="codeBlockLines_RjmQ"><spanclass="token-line"style="color:#393A34"><spanclass="token keyword"style="color:#00009f">import</span><spanclass="token plain"> puppeteer </span><spanclass="token keyword"style="color:#00009f">from</span><spanclass="token plain"></span><spanclass="token string"style="color:#e3116c">'puppeteer'</span><spanclass="token punctuation"style="color:#393A34">;</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"style="display:inline-block"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">const</span><spanclass="token plain"> browser </span><spanclass="token operator"style="color:#393A34">=</span><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">await</span><spanclass="token plain"> puppeteer</span><spanclass="token punctuation"style="color:#393A34">.</span><spanclass="token function"style="color:#d73a49">launch</span><spanclass="token punctuation"style="color:#393A34">(</span><spanclass="token punctuation"style="color:#393A34">)</span><spanclass="token punctuation"style="color:#393A34">;</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token comment"style="color:#999988;font-style:italic">// Store the endpoint to be able to reconnect to the browser.</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">const</span><spanclass="token plain"> browserWSEndpoint </span><spanclass="token operator"style="color:#393A34">=</span><spanclass="token plain"> browser</span><spanclass="token punctuation"style="color:#393A34">.</span><spanclass="token function"style="color:#d73a49">wsEndpoint</span><spanclass="token punctuation"style="color:#393A34">(</span><spanclass="token punctuation"style="color:#393A34">)</span><spanclass="token punctuation"style="color:#393A34">;</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token comment"style="color:#999988;font-style:italic">// Disconnect puppeteer from the browser.</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">await</span><spanclass="token plain"> browser</span><spanclass="token punctuation"style="color:#393A34">.</span><spanclass="token function"style="color:#d73a49">disconnect</span><spanclass="token punctuation"style="color:#393A34">(</span><spanclass="token punctuation"style="color:#393A34">)</span><spanclass="token punctuation"style="color:#393A34">;</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"style="display:inline-block"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token comment"style="color:#999988;font-style:italic">// Use the endpoint to reestablish a connection</span><spanclass="token plain"></span><br></span><spanclass="token-line"style="color:#393A34"><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">const</span><spanclass="token plain"> browser2 </span><spanclass="token operator"style="color:#393A34">=</span><spanclass="token plain"></span><spanclass="token keyword"style="color:#00009f">await</span><spanclass="token plain"> puppeteer</span><spanclass="token punctuation"sty
<h2class="anchor anchorWithStickyNavbar_FNw8"id="properties">Properties<ahref="#properties"class="hash-link"aria-label="Direct link to Properties"title="Direct link to Properties"></a></h2>
<table><thead><tr><th><p>Property</p></th><th><p>Modifiers</p></th><th><p>Type</p></th><th><p>Description</p></th></tr></thead><tbody><tr><td><spanid="connected">connected</span></td><td><p><code>readonly</code></p></td><td><p>boolean</p></td><td><p>Whether Puppeteer is connected to this <ahref="/next/api/puppeteer.browser">browser</a>.</p></td></tr><tr><td><spanid="debuginfo">debugInfo</span></td><td><p><code>readonly</code></p></td><td><p><ahref="/next/api/puppeteer.debuginfo">DebugInfo</a></p></td><td><p><strong><em>(Experimental)</em></strong> Get debug information from Puppeteer.</p><p><strong>Remarks:</strong></p><p>Currently, includes pending protocol calls. In the future, we might add more info.</p></td></tr></tbody></table>
<h2class="anchor anchorWithStickyNavbar_FNw8"id="methods">Methods<ahref="#methods"class="hash-link"aria-label="Direct link to Methods"title="Direct link to Methods"></a></h2>
<table><thead><tr><th><p>Method</p></th><th><p>Modifiers</p></th><th><p>Description</p></th></tr></thead><tbody><tr><td><spanid="browsercontexts"><ahref="/next/api/puppeteer.browser.browsercontexts">browserContexts()</a></span></td><td></td><td><p>Gets a list of open <ahref="/next/api/puppeteer.browsercontext">browser contexts</a>.</p><p>In a newly-created <ahref="/next/api/puppeteer.browser">browser</a>, this will return a single instance of <ahref="/next/api/puppeteer.browsercontext">BrowserContext</a>.</p></td></tr><tr><td><spanid="close"><ahref="/next/api/puppeteer.browser.close">close()</a></span></td><td></td><td><p>Closes this <ahref="/next/api/puppeteer.browser">browser</a> and all associated <ahref="/next/api/puppeteer.page">pages</a>.</p></td></tr><tr><td><spanid="createbrowsercontext"><ahref="/next/api/puppeteer.browser.createbrowsercontext">createBrowserContext(options)</a></span></td><td></td><td><p>Creates a new <ahref="/next/api/puppeteer.browsercontext">browser context</a>.</p><p>This won't share cookies/cache with other <ahref="/next/api/puppeteer.browsercontext">browser contexts</a>.</p></td></tr><tr><td><spanid="defaultbrowsercontext"><ahref="/next/api/puppeteer.browser.defaultbrowsercontext">defaultBrowserContext()</a></span></td><td></td><td><p>Gets the default <ahref="/next/api/puppeteer.browsercontext">browser context</a>.</p><p><strong>Remarks:</strong></p><p>The default <ahref="/next/api/puppeteer.browsercontext">browser context</a> cannot be closed.</p></td></tr><tr><td><spanid="disconnect"><ahref="/next/api/puppeteer.browser.disconnect">disconnect()</a></span></td><td></td><td><p>Disconnects Puppeteer from this <ahref="/next/api/puppeteer.browser">browser</a>, but leaves the process running.</p></td></tr><tr><td><spanid="isconnected"><ahref="/next/api/puppeteer.browser.isconnected">isConnected()</a></span></td><td><p><code>deprecated</code></p></td><td><p>Whether Puppeteer is connected to this <ahref="/next/api/puppeteer.browser">browser</a>.</p><p><strong>Deprecated:</strong></p><p>Use <ahref="/next/api/puppeteer.browser">Browser.connected</a>.</p></td></tr><tr><td><spanid="newpage"><ahref="/next/api/puppeteer.browser.newpage">newPage()</a></span></td><td></td><td><p>Creates a new <ahref="/next/api/puppeteer.page">page</a> in the <ahref="/next/api/puppeteer.browser.defaultbrowsercontext">default browser context</a>.</p></td></tr><tr><td><spanid="pages"><ahref="/next/api/puppeteer.browser.pages">pages()</a></span></td><td></td><td><p>Gets a list of all open <ahref="/next/api/puppeteer.page">pages</a> inside this <ahref="/next/api/puppeteer.browser">Browser</a>.</p><p>If there ar multiple <ahref="/next/api/puppeteer.browsercontext">browser contexts</a>, this returns all <ahref="/next/api/puppeteer.page">pages</a> in all <ahref="/next/api/puppeteer.browsercontext">browser contexts</a>.</p><p><strong>Remarks:</strong></p><p>Non-visible <ahref="/next/api/puppeteer.page">pages</a>, such as <code>"background_page"</code>, will not be listed here. You can find them using <ahref="/next/api/puppeteer.target.page">Target.page()</a>.</p></td></tr><tr><td><spanid="process"><ahref="/next/api/puppeteer.browser.process">process()</a></span></td><td></td><td><p>Gets the associated <ahref="https://nodejs.org/api/child_process.html#class-childprocess"target="_blank"rel="noopener noreferrer">ChildProcess</a>.</p></td></tr><tr><td><spanid="target"><ahref="/next/api/puppeteer.browser.target">target()</a></span></td><td></td><td><p>Gets the <ahref="/next/api/puppeteer.target">target</a> associated with the <ahref="/next/api/puppeteer.browser.defaultbrowsercontext">default browser context</a>).</p></td></tr><tr><td><spanid="targets"><ahref="/next/api/puppeteer.browser.targets">targets()</a></span></td><td></td><td><p>Gets all active <ahref="/next/api/puppeteer.target">targets</a>.</p><p>In case of multiple <ahref="/next/api/puppeteer.browsercontext">browser contexts</a>, this returns all <ahref="/next/api/puppeteer.target">targets</a> in all <ahref="