<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/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="2"><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/api/puppeteer.browser"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/api/puppeteer.browser"hreflang="en"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/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="/api/puppeteer.browser">Browser</a> represents a browser instance that is either:</p>
<ul>
<li>connected to via <ahref="/api/puppeteer.puppeteer.connect">Puppeteer.connect()</a> or - launched by <ahref="/api/puppeteer.puppeteernode.launch">PuppeteerNode.launch()</a>.</li>
</ul>
<p><ahref="/api/puppeteer.browser">Browser</a><ahref="/api/puppeteer.eventemitter">emits</a> various events which are documented in the <ahref="/api/puppeteer.browserevent">BrowserEvent</a> enum.</p>
<h4class="anchor anchorWithStickyNavbar_LWe7"id="signature">Signature:<ahref="#signature"class="hash-link"aria-label="Direct link to Signature:"title="Direct link to Signature:"></a></h4>
<h2class="anchor anchorWithStickyNavbar_LWe7"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_LWe7"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>
<p>Using a <ahref="/api/puppeteer.browser">Browser</a> to create a <ahref="/api/puppeteer.page">Page</a>:</p>
<h2class="anchor anchorWithStickyNavbar_LWe7"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>
<p>Disconnecting from and reconnecting to a <ahref="/api/puppeteer.browser">Browser</a>:</p>
<divclass="language-ts codeBlockContainer_Ckt0 theme-code-block"style="--prism-color:#393A34;--prism-background-color:#f6f8fa"><divclass="codeBlockContent_biex"><pretabindex="0"class="prism-code language-ts codeBlock_bY9V thin-scrollbar"style="color:#393A34;background-color:#f6f8fa"><codeclass="codeBlockLines_e6Vv"><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">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"style="color:#393A34">.</span><spanclass="token function"style="color:#d73a49">connect</span><spa
<h2class="anchor anchorWithStickyNavbar_LWe7"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>Property</th><th>Modifiers</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td>connected</td><td><code>readonly</code></td><td>boolean</td><td>Whether Puppeteer is connected to this <ahref="/api/puppeteer.browser">browser</a>.</td></tr></tbody></table>
<h2class="anchor anchorWithStickyNavbar_LWe7"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>Method</th><th>Modifiers</th><th>Description</th></tr></thead><tbody><tr><td><ahref="/api/puppeteer.browser.browsercontexts">browserContexts()</a></td><td></td><td><p>Gets a list of open <ahref="/api/puppeteer.browsercontext">browser contexts</a>.</p><p>In a newly-created <ahref="/api/puppeteer.browser">browser</a>, this will return a single instance of <ahref="/api/puppeteer.browsercontext">BrowserContext</a>.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.close">close()</a></td><td></td><td>Closes this <ahref="/api/puppeteer.browser">browser</a> and all associated <ahref="/api/puppeteer.page">pages</a>.</td></tr><tr><td><ahref="/api/puppeteer.browser.createincognitobrowsercontext">createIncognitoBrowserContext(options)</a></td><td></td><td><p>Creates a new incognito <ahref="/api/puppeteer.browsercontext">browser context</a>.</p><p>This won't share cookies/cache with other <ahref="/api/puppeteer.browsercontext">browser contexts</a>.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.defaultbrowsercontext">defaultBrowserContext()</a></td><td></td><td>Gets the default <ahref="/api/puppeteer.browsercontext">browser context</a>.</td></tr><tr><td><ahref="/api/puppeteer.browser.disconnect">disconnect()</a></td><td></td><td>Disconnects Puppeteer from this <ahref="/api/puppeteer.browser">browser</a>, but leaves the process running.</td></tr><tr><td><ahref="/api/puppeteer.browser.isconnected">isConnected()</a></td><td></td><td>Whether Puppeteer is connected to this <ahref="/api/puppeteer.browser">browser</a>.</td></tr><tr><td><ahref="/api/puppeteer.browser.newpage">newPage()</a></td><td></td><td>Creates a new <ahref="/api/puppeteer.page">page</a> in the <ahref="/api/puppeteer.browser.defaultbrowsercontext">default browser context</a>.</td></tr><tr><td><ahref="/api/puppeteer.browser.pages">pages()</a></td><td></td><td><p>Gets a list of all open <ahref="/api/puppeteer.page">pages</a> inside this <ahref="/api/puppeteer.browser">Browser</a>.</p><p>If there ar multiple <ahref="/api/puppeteer.browsercontext">browser contexts</a>, this returns all <ahref="/api/puppeteer.page">pages</a> in all <ahref="/api/puppeteer.browsercontext">browser contexts</a>.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.process">process()</a></td><td></td><td>Gets the associated <ahref="https://nodejs.org/api/child_process.html#class-childprocess"target="_blank"rel="noopener noreferrer">ChildProcess</a>.</td></tr><tr><td><ahref="/api/puppeteer.browser.target">target()</a></td><td></td><td>Gets the <ahref="/api/puppeteer.target">target</a> associated with the <ahref="/api/puppeteer.browser.defaultbrowsercontext">default browser context</a>).</td></tr><tr><td><ahref="/api/puppeteer.browser.targets">targets()</a></td><td></td><td><p>Gets all active <ahref="/api/puppeteer.target">targets</a>.</p><p>In case of multiple <ahref="/api/puppeteer.browsercontext">browser contexts</a>, this returns all <ahref="/api/puppeteer.target">targets</a> in all <ahref="/api/puppeteer.browsercontext">browser contexts</a>.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.useragent">userAgent()</a></td><td></td><td><p>Gets this <ahref="/api/puppeteer.browser">browser's</a> original user agent.</p><p><ahref="/api/puppeteer.page">Pages</a> can override the user agent with <ahref="/api/puppeteer.page.setuseragent">Page.setUserAgent()</a>.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.version">version()</a></td><td></td><td><p>Gets a string representing this <ahref="/api/puppeteer.browser">browser's</a> name and version.</p><p>For headless browser, this is similar to <code>"HeadlessChrome/61.0.3153.0"</code>. For non-headless or new-headless, this is similar to <code>"Chrome/61.0.3153.0"</code>. For Firefox, it is similar to <code>"Firefox/116.0a1"</code>.</p><p>The format of <ahref="/api/puppeteer.browser.version">Browser.version()</a> might change with future releases of browsers.</p></td></tr><tr><td><ahref="/api/puppeteer.browser.waitfortarget">waitFo