<titledata-rh="true">Target 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.target"><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="Target class | Puppeteer"><metadata-rh="true"name="description"content="Target represents a CDP target. In CDP a target is something that can be debugged such a frame, a page or a worker."><metadata-rh="true"property="og:description"content="Target represents a CDP target. In CDP a target is something that can be debugged such a frame, a page or a worker."><linkdata-rh="true"rel="icon"href="/img/favicon.ico"><linkdata-rh="true"rel="canonical"href="https://pptr.dev/api/puppeteer.target"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/api/puppeteer.target"hreflang="en"><linkdata-rh="true"rel="alternate"href="https://pptr.dev/api/puppeteer.target"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>Target represents a <ahref="https://chromedevtools.github.io/devtools-protocol/tot/Target/"target="_blank"rel="noopener noreferrer">CDP target</a>. In CDP a target is something that can be debugged such a frame, a page or a worker.</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>Target</code> class.</p>
<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="aspage"><ahref="/api/puppeteer.target.aspage">asPage()</a></span></td><td></td><td><p>Forcefully creates a page for a target of any type. It is useful if you want to handle a CDP target of type <code>other</code> as a page. If you deal with a regular page target, use <ahref="/api/puppeteer.target.page">Target.page()</a>.</p></td></tr><tr><td><spanid="browser"><ahref="/api/puppeteer.target.browser">browser()</a></span></td><td></td><td><p>Get the browser the target belongs to.</p></td></tr><tr><td><spanid="browsercontext"><ahref="/api/puppeteer.target.browsercontext">browserContext()</a></span></td><td></td><td><p>Get the browser context the target belongs to.</p></td></tr><tr><td><spanid="createcdpsession"><ahref="/api/puppeteer.target.createcdpsession">createCDPSession()</a></span></td><td></td><td><p>Creates a Chrome Devtools Protocol session attached to the target.</p></td></tr><tr><td><spanid="opener"><ahref="/api/puppeteer.target.opener">opener()</a></span></td><td></td><td><p>Get the target that opened this target. Top-level targets return <code>null</code>.</p></td></tr><tr><td><spanid="page"><ahref="/api/puppeteer.target.page">page()</a></span></td><td></td><td><p>If the target is not of type <code>"page"</code>, <code>"webview"</code> or <code>"background_page"</code>, returns <code>null</code>.</p></td></tr><tr><td><spanid="type"><ahref="/api/puppeteer.target.type">type()</a></span></td><td></td><td><p>Identifies what kind of target this is.</p><p><strong>Remarks:</strong></p><p>See <ahref="https://developer.chrome.com/extensions/background_pages"target="_blank"rel="noopener noreferrer">docs</a> for more info about background pages.</p></td></tr><tr><td><spanid="url"><ahref="/api/puppeteer.target.url">url()</a></span></td><td></td><td></td></tr><tr><td><spanid="worker"><ahref="/api/puppeteer.target.worker">worker()</a></span></td><td></td><td><p>If the target is not of type <code>"service_worker"</code> or <code>"shared_worker"</code>, returns <code>null</code>.</p></td></tr></tbody></table></div></article><navclass="pagination-nav docusaurus-mt-lg"aria-label="Docs pages"><aclass="pagination-nav__link pagination-nav__link--prev"href="/api/puppeteer.securitydetails.validto"><divclass="pagination-nav__sublabel">Previous</div><divclass="pagination-nav__label">SecurityDetails.validTo</div></a><aclass="pagination-nav__link pagination-nav__link--next"href="/api/puppeteer.target.aspage"><divclass="pagination-nav__sublabel">Next</div><divclass="pagination-nav__label">Target.asPage</div></a></nav></div></div><divclass="col col--3"><divclass="tableOfContents_IS5x thin-scrollbar theme-doc-toc-desktop"><ulclass="table-of-contents table-of-contents__left-border"><li><ahref="#remarks"class="table-of-contents__link toc-highlight">Remarks</a></li><li><ahref="#methods"class="table-of-contents__link toc-highlight">Methods</a></li></ul></div></div></div></div></main></div></div></div><footerclass="footer footer--dark"><divclass="container container-fluid"><divclass="row footer__links"><divclass="col footer__col"><divclass="footer__title">Community</div><ulclass="footer__items clean-list"><liclass="footer__item"><ahref="https://stackoverflow.com/questions/tagged/puppeteer"target="_blank"rel="noopener noreferrer"class="footer__link-item">Stack Overflow<svgwidth="13.5"height="13.5"aria-hidden="true"viewBox="0 0 24 24"class="iconExternalLink_T11m"><pathfill="currentColor"d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><liclass="footer__item"><ahref="https://twitter.com/chromedevtools"target="_blank"rel="noopener noreferrer"class="footer__link-item">Twitter<svgwidth="13.5"height="13.5"aria-hidden="true"viewBox="0 0 24 24"class="iconExternalLink_T11m"><pathfill="currentColor"d="M2113v10h-21v-19h12v2h-10