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

To automate multiple tabs, create multiple Page objects inside one browser context when they belong to the same user session. Create separate contexts when the pages must represent independent users or isolated sessions. In Playwright, a page is a tab-like interaction target; the context is the session boundary. This distinction also makes popup handling and cleanup easier to reason about.

How do I automate multiple tabs in a browser?

Use one browser instance, create a browser context for each independent session, then create one or more pages in each context. A Playwright browser can have multiple Page instances. Pages in the same context share the browser session; different contexts isolate session state. Playwright describes contexts as isolated, clean-slate environments with separate cookies, local storage, and session storage. Puppeteer likewise documents context separation for cookies and local storage. Playwright: Pages · Playwright: Browser contexts · Puppeteer: BrowserContext

  • Same user, multiple tabs: use multiple pages in one context.
  • Different users or isolated sessions: use one context per user, even if both contexts run in the same browser.
  • Popup opened by a page: expect it to belong to the opener’s context, not to become a separate user session.

This model suits UI tests that open new tabs, scripts that inspect several pages as the same signed-in user, and multi-user tests such as an administrator interacting with a regular user. Playwright specifically describes multiple contexts in one scenario as a way to model separate users, including chat participants. Playwright: browser contexts and isolation

Should I use a new page or a new browser context?

Need Choose Reason
Open or control another tab for the same user Another page in the existing context The pages remain in the same session.
Handle a popup created by the current page The popup page in the opener’s context Playwright documents that a popup belongs to its opener’s browser context.
Run a second user, account, or isolated test session A new context, then a page in it Separate contexts keep session state independent without requiring another browser instance.
Run a short, single-page snippet browser.newPage() may be convenient in Playwright Playwright documents it as a convenience for short snippets and single-page scenarios; explicit contexts provide tighter lifecycle control.

Do not create a new context merely because a flow has another tab. That can break a workflow that relies on the same login or other session state. Conversely, a second page is not a substitute for a separate context when you need independent users: pages in the same context are part of the same session.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Playwright example: multiple tabs and isolated users

The following JavaScript example uses the Playwright library with Chromium. It creates two isolated user contexts, opens multiple pages for one user, waits for a popup before clicking the opener, checks the resulting page, and closes resources in a finally block. Install Playwright with npm install playwright; install its browser binaries with npx playwright install chromium. Replace the example URLs and selectors with those used by your application.

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({ headless: true });
  const contexts = [];

  try {
    // Separate contexts represent separate users/sessions.
    const adminContext = await browser.newContext();
    contexts.push(adminContext);
    const userContext = await browser.newContext();
    contexts.push(userContext);

    // Multiple tabs for the same user live in the same context.
    const adminPage = await adminContext.newPage();
    const adminReportPage = await adminContext.newPage();
    const userPage = await userContext.newPage();

    await Promise.all([
      adminPage.goto('https://example.com/admin', { waitUntil: 'domcontentloaded' }),
      adminReportPage.goto('https://example.com/admin/reports', { waitUntil: 'domcontentloaded' }),
      userPage.goto('https://example.com/account', { waitUntil: 'domcontentloaded' }),
    ]);

    // Register the popup wait before the action that opens it.
    const popupPromise = adminPage.waitForEvent('popup');
    await adminPage.getByRole('link', { name: 'Open report' }).click();
    const popup = await popupPromise;

    // A popup is a page in the opener's context.
    if (popup.context() !== adminContext) {
      throw new Error('Popup opened in an unexpected browser context');
    }

    await popup.waitForLoadState('domcontentloaded');
    console.log('Popup URL:', popup.url());
    console.log('Admin tab URL:', adminReportPage.url());
    console.log('User tab URL:', userPage.url());

    // Assert each page independently; use application-specific expectations.
    await adminPage.getByRole('heading', { name: 'Admin' }).waitFor();
    await popup.getByRole('heading', { name: 'Report' }).waitFor();
    await userPage.getByRole('heading', { name: 'Account' }).waitFor();
  } finally {
    // Close contexts before the browser so their pages and session state are released.
    for (const context of contexts.reverse()) {
      await context.close();
    }
    await browser.close();
  }
})();

The example deliberately waits for the popup event before clicking. If the listener is attached only after the click, a fast popup can appear before the script starts waiting. The context check makes the intended session relationship explicit. For production test suites, use the framework’s assertion and fixture facilities where available, while preserving the same page/context ownership model. Playwright recommends explicit context lifecycle management in production code and test frameworks. Playwright BrowserContext API · Playwright Browser API

Handling popups and newly created pages

There are two related cases: a page opens a popup, or your code creates another page directly. In the first case, register a popup listener on the opener before performing the action. In the second, call newPage() on the intended context and retain the returned page reference. Keep the reference rather than guessing which page is newest when several pages may be created.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
  1. Identify which existing page performs the action.
  2. Start waiting for that page’s popup event before clicking or submitting.
  3. Trigger the action that opens the new page.
  4. Wait for the resulting page to reach the state your script needs, and assert its URL or visible content.
  5. Check that it belongs to the expected context if session ownership matters.

Do not assume that a popup is ready for interaction as soon as its event fires. The new page may still be navigating; wait for an appropriate load state or a specific application element. A URL check alone also does not prove the page is usable, so assert a visible page-specific condition before continuing.

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

When to use Playwright or Puppeteer

Both Playwright and Puppeteer support multiple pages and context-based session separation. The choice depends on your project’s actual needs: required browser engines, language and test-runner integration, popup behavior, debugging and trace support, and the team’s existing familiarity. The documentation cited here establishes the page/context model, not a complete current comparison of those capabilities or a performance ranking. Playwright Pages · Puppeteer browser management

For Puppeteer, the same design rule applies: use a new page within a context for another page in that session, and use separate browser contexts to isolate tasks. Puppeteer’s documentation says to use BrowserContexts when isolation is needed. The exact event-waiting code depends on the framework and binding you choose; consult the current API documentation rather than copying a Playwright-specific snippet into Puppeteer. Puppeteer browser management

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Lifecycle, performance, and reliability

Own the context lifecycle

Contexts define both the session boundary and a useful cleanup boundary. Keep track of contexts created by the test or job, close them when their work is done, and close the browser after its contexts have been cleaned up. Explicit ownership prevents pages from being left open between tasks and makes it clear which user’s pages are being managed. Playwright identifies explicit context lifetime control as useful in production code and test frameworks. Playwright Browser API

Prefer the smallest correct session structure

Use one browser with the number of contexts and pages the scenario needs; the documented relationship lets multiple user sessions be modeled in one browser. The cited documentation does not establish a universal maximum page count, speed advantage, or resource cost for a given number of pages or contexts. In practice, monitor your own workload and avoid opening pages that the scenario does not need.

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

Wait for the condition that matters

Navigation completion, network quiet, and application readiness are not interchangeable. A page may finish its initial navigation before client-side content appears. Where possible, wait for a page-specific selector or state rather than relying on a fixed sleep. For popup flows, start listening before triggering the action, then wait for the popup’s relevant content before interacting.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting multi-page automation

  • The popup wait times out: verify the click actually opens a new page and that the listener is attached to the page that triggers it. Attach the wait before the action, and check whether the site instead navigates the current page.
  • The script uses the wrong page: retain the page returned by newPage() or by the popup wait. Avoid selecting a page by array position when page creation order can change.
  • A second user appears signed in as the first: create a separate browser context for each user. Creating another page in the same context does not create an independent session.
  • A popup cannot see the expected session: confirm which page opened it and verify that the popup belongs to the opener’s context. Do not assume it was created in a separately isolated context.
  • Element lookup fails after navigation: wait for the relevant load state or an application-specific selector before locating the element; confirm the page is the expected one by checking its URL and visible state.
  • Tests interfere with one another: check that contexts are not being reused when tests require isolation, and close each context in a guaranteed cleanup path.

Or skip the browser setup

If the task is to capture a website rather than interact with multiple live pages, ScreenshotNeo offers a one-request screenshot API. The call below returns an image; see the ScreenshotNeo API documentation for parameters and response details.

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 or consent banners as a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with the result indicated by X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots.

Sign up free for 1,000 screenshots a month, no card required.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Frequently asked questions

Can separate browser contexts run in one browser?

Yes. The context is the isolated session boundary; multiple contexts can represent separate users in one browser instance.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Does a popup automatically create a new user session?

No. In Playwright, a popup belongs to the browser context of the page that opened it.

Should I use browser.newPage() in a test suite?

Playwright presents it as a convenience for short snippets and single-page scenarios. Explicitly creating and closing contexts gives tighter lifecycle control for production code and test frameworks.

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.

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