Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk2 min

How to List Targets in a Puppeteer BrowserContext

Call context.targets() to synchronously list active Puppeteer targets scoped to one BrowserContext. Learn how it differs from pages() and browser.targets().
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call context.targets() on the Puppeteer BrowserContext you want to inspect. It synchronously returns a Target[] for the active targets in that context.

List targets in one BrowserContext

Keep a reference to the context you want to inspect, then call its targets() method:

As an Amazon Associate I earn from qualifying purchases.

const targets = context.targets();
console.log(targets);

The documented signature is targets(): Target[], so you do not use await. The result is a snapshot of the targets active when you call the method.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Runnable example

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const context = await browser.createBrowserContext();
  const targets = context.targets();

  console.log(`Active targets in this context: ${targets.length}`);
  for (const target of targets) {
    console.log(target.type(), target.url());
  }
} finally {
  await browser.close();
}

createBrowserContext() creates an isolated browser context. Closing the browser closes its associated pages; the finally block ensures cleanup if inspection or logging fails.

Choose targets, pages, or browser-wide targets

Need Use What it returns or covers
Every active target in one context context.targets() Synchronous Target[] scoped to that context.
Open pages in one context await context.pages() Asynchronous Page[]. By default, non-visible pages such as background pages are omitted.
Targets throughout the browser browser.targets() Targets from all browser contexts, not just one.
Open contexts in the browser browser.browserContexts() The browser’s BrowserContext objects.

Use context.targets() when scope matters and you need targets rather than only pages. Use pages() when you want page objects and its default visibility behavior is suitable. The includeAll option for pages() is documented as experimental.

Understand context scope

A BrowserContext isolates browser storage from other contexts. A popup opened by a page belongs to the same context as its opener. Consequently, calling targets() on that context includes its active targets, while calling browser.targets() deliberately broadens the scope to the entire browser.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

If you have multiple contexts, retain the specific context reference associated with the work you are inspecting. Do not substitute the browser-wide method if your requirement is to exclude other contexts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Common mistakes and fixes

  • Using await context.targets(): targets() is synchronous and returns an array directly. Remove await.
  • Getting more targets than expected: browser.targets() spans all contexts. Call targets() on the intended context instead.
  • Missing a background target when using pages(): pages() omits non-visible pages by default. Use context.targets() to enumerate active targets, or inspect a target with Target.page() where appropriate.
  • Expecting targets opened later to appear in an earlier result: the returned array reflects the call time. Call context.targets() again after the target is created.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website screenshot rather than Puppeteer target inspection, ScreenshotNeo provides a screenshot API and MCP server. A single request can return an image or PDF; it does not expose Puppeteer Target objects.

cURL example (see the ScreenshotNeo API documentation for options):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie banners and removes known consent banners, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server includes screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month without a card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.