<titledata-rh="true">Page 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.page"><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="Page class | Puppeteer"><metadata-rh="true"name="description"content="Page provides methods to interact with a single tab or extension background page in the browser."><metadata-rh="true"property="og:description"content="Page provides methods to interact with a single tab or extension background page in the browser."><linkdata-rh="true"rel="icon"href="/img/favicon.ico"><linkdata-rh="true"rel="canonical"href="https://pptr.dev/next/api/puppeteer.page"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.page"hreflang="en"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/next/api/puppeteer.page"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>Page provides methods to interact with a single tab or <ahref="https://developer.chrome.com/extensions/background_pages"target="_blank"rel="noopener noreferrer">extension background page</a> in the browser.</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>Page</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>This example creates a page, navigates it to a URL, and then saves a screenshot:</p>
<p>The Page class extends from Puppeteer's <ahref="/next/api/puppeteer.eventemitter">EventEmitter</a> class and will emit various events which are documented in the <ahref="/next/api/puppeteer.pageevent">PageEvent</a> enum.</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>This example logs a message for a single page <code>load</code> event:</p>
<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>accessibility</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.accessibility">Accessibility</a></td><td>The Accessibility class provides methods for inspecting the browser's accessibility tree. The accessibility tree is used by assistive technology such as <ahref="https://en.wikipedia.org/wiki/Screen_reader"target="_blank"rel="noopener noreferrer">screen readers</a> or <ahref="https://en.wikipedia.org/wiki/Switch_access"target="_blank"rel="noopener noreferrer">switches</a>.</td></tr><tr><td>coverage</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.coverage">Coverage</a></td><td>The Coverage class provides methods to gather information about parts of JavaScript and CSS that were used by the page.</td></tr><tr><td>keyboard</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.keyboard">Keyboard</a></td><td>Keyboard provides an api for managing a virtual keyboard. The high level api is <ahref="/next/api/puppeteer.keyboard.type">Keyboard.type()</a>, which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.</td></tr><tr><td>mouse</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.mouse">Mouse</a></td><td>The Mouse class operates in main-frame CSS pixels relative to the top-left corner of the viewport.</td></tr><tr><td>touchscreen</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.touchscreen">Touchscreen</a></td><td>The Touchscreen class exposes touchscreen events.</td></tr><tr><td>tracing</td><td><code>readonly</code></td><td><ahref="/next/api/puppeteer.tracing">Tracing</a></td><td>The Tracing class exposes the tracing audit interface.</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="/next/api/puppeteer.page._">$</a></td><td></td><td>Runs <code>document.querySelector</code> within the page. If no element matches the selector, the return value resolves to <code>null</code>.</td></tr><tr><td><ahref="/next/api/puppeteer.page.__">$$</a></td><td></td><td>The method runs <code>document.querySelectorAll</code> within the page. If no elements match the selector, the return value resolves to <code>[]</code>.</td></tr><tr><td><ahref="/next/api/puppeteer.page.__eval">$$eval</a></td><td></td><td>This method runs <code>Array.from(document.querySelectorAll(selector))</code> within the page and passes the result as the first argument to the <code>pageFunction</code>.</td></tr><tr><td><ahref="/next/api/puppeteer.page._eval">$eval</a></td><td></td><td>This method runs <code>document.querySelector</code> within the page and passes the result as the first argument to the <code>pageFunction</code>.</td></tr><tr><td><ahref="/next/api/puppeteer.page._x">$x</a></td><td></td><td>The method evaluates the XPath expression relative to the page document as its context node. If there are no such elements, the method resolves to an empty array.</td></tr><tr><td><ahref="/next/api/puppeteer.page.addscripttag">addScriptTag</a></td><td></td><td>Adds a <code><script></code> tag into the page with the desired URL or content.</td></tr><tr><td><ahref="/next/api/puppeteer.page.addstyletag">addStyleTag</a></td><td></td><td><p>Adds a <code><link rel="stylesheet"></code> tag into the page with the desired URL or a <code><style type="text/css"></code> tag with the content.</p><p>Shortcut for <ahref="/next/api/puppeteer.frame.addstyletag_1">page.mainFrame().addStyleTag(options)</a>.</p></td></tr><tr><td><ahref="/next/api/puppeteer.page.addstyletag_1">addStyleTag</a></td><td></td><td></td></tr><tr><td><ahref="/next/api/puppeteer.page.authenticate">authenticate</a></td><td></td><td>Provide credentials for <code>HTTP authentication</code>.</td></tr><tr><td><ahref="/next/api/puppeteer.page.bringtofront">bringToFront</a></td><td></td><td>Brings page to front (activates tab).</td></tr><tr><td><ahref="/next/api/puppeteer.page.browser">browser</a></td><td></td><td>Get the browser the page belongs to.</td></tr><tr><td><ahref="/next/api/puppeteer.page.browsercontext">browserContext</a></td><td></td><td>Get the browser context that the page belongs to.</td></tr><tr><td><ahref="/next/api/puppeteer.page.click">click</a></td><td></td><td>This method fetches an element with <code>selector</code>, scrolls it into view if needed, and then uses <ahref="/next/api/puppeteer.page">Page.mouse</a> to click in the center of the element. If there's no element matching <code>selector</code>, the method throws an error.</td></tr><tr><td><ahref="/next/api/puppeteer.page.close">close</a></td><td></td><td></td></tr><tr><td><ahref="/next/api/puppeteer.page.content">content</a></td><td></td><td>The full HTML contents of the page, including the DOCTYPE.</td></tr><tr><td><ahref="/next/api/puppeteer.page.cookies">cookies</a></td><td></td><td>If no URLs are specified, this method returns cookies for the current page URL. If URLs are specified, only cookies for those URLs are returned.</td></tr><tr><td><ahref="/next/api/puppeteer.page.createcdpsession">createCDPSession</a></td><td></td><td>Creates a Chrome Devtools Protocol session attached to the page.</td></tr><tr><td><ahref="/next/api/puppeteer.page.createpdfstream">createPDFStream</a></td><td></td><td>Generates a PDF of the page with the <code>print</code> CSS media type.</td></tr><tr><td><ahref="/next/api/puppeteer.page.deletecookie">deleteCookie</a></td><td></td><td></td></tr><tr><td><ahref="/next/api/puppeteer.page.emulate">emulate</a></td><td></td><td><p>Emulates a given device's metrics and user agent.</p><p>To aid emulation, Puppeteer provides a list of known devices that can be via <ahref="/next/api/puppeteer.knowndevices">KnownDevices</a>.</p