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

To automate multiple tabs, create multiple Page objects in one browser context when they belong to the same user session. Create a separate browser context for each independent user or session. A page is a tab or page target; a context is the session boundary that determines whether cookies and other state are shared.

This distinction makes popup handling, multi-user tests, and cleanup easier to reason about. The examples below use Playwright’s JavaScript API; the same page-versus-context model also appears in Puppeteer.

How do I automate multiple tabs in a browser?

Start one browser, create the session boundary or boundaries your scenario needs, then create pages inside them. For two tabs used by the same signed-in user, put both pages in the same context. For an admin and a regular user, use two contexts in the same browser so their sessions remain separate.

  1. Create or obtain a browser instance.
  2. Create one context for each independent session or user.
  3. Create one or more pages in each context.
  4. Register popup or page-event handling before the action that opens a page.
  5. Check each page’s URL and visible state independently.
  6. Close contexts and then the browser in a controlled cleanup path.

Playwright describes a Page as a single tab or page and allows a browser to have multiple pages. Its isolation guide describes contexts as clean-slate environments with separate cookies, local storage, and session storage. See Playwright Page documentation and Playwright’s isolation guide (accessed September 29, 2026).

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

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

Need Use Why
Another tab for the same user, including a page opened as a popup A new page in the existing context The pages remain in the same browser session.
A second user, such as an administrator alongside a regular user A new context in the same browser Each context has independent session state without requiring another browser instance.
A short, single-page snippet Playwright’s browser.newPage() convenience method may be suitable For production and test-framework code, explicit contexts give tighter control over lifetime and cleanup.

Playwright states that a popup opened by a page belongs to that page’s browser context. Puppeteer likewise documents context isolation: cookies and local storage are not shared across contexts. See Playwright BrowserContext API and Puppeteer BrowserContext.pages() API (version 25.11.0 displayed; accessed September 29, 2026).

Playwright example: two pages in one session

This runnable Node.js example uses Playwright’s documented browser, context, and page objects. Install the package and a browser first using the Playwright installation guide. Replace the example URL with an accessible site and adapt the checks to its content.

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

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();

  try {
    const firstTab = await context.newPage();
    await firstTab.goto('https://example.com');

    const secondTab = await context.newPage();
    await secondTab.goto('https://example.com');

    console.log('First tab:', firstTab.url());
    console.log('Second tab:', secondTab.url());
    console.log('Pages in this session:', context.pages().length);
  } finally {
    await context.close();
    await browser.close();
  }
})();

Both pages are in the same context, so they share that session’s cookies and storage. If the flow signs in on one page and opens another page for the same user, use this arrangement. Avoid treating a second tab as a second user: it is not an isolated session.

How do I handle a popup in Playwright?

Wait for the popup event before performing the action that opens it. This ordering avoids missing a fast popup. The event is associated with the opener page, and Playwright documents that the popup belongs to the opener’s context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();

  try {
    const opener = await context.newPage();
    await opener.goto('https://example.com');

    // Replace this selector with the link or button that opens the popup.
    const popupPromise = opener.waitForEvent('popup');
    await opener.getByRole('link', { name: 'Open details' }).click();
    const popup = await popupPromise;

    await popup.waitForLoadState();
    console.log('Popup URL:', popup.url());
    console.log('Popup shares opener context:', popup.context() === context);
  } finally {
    await context.close();
    await browser.close();
  }
})();

The locator is illustrative: use a role and accessible name that match the actual page, or another stable locator appropriate to the application. If the action can open a new page without being a popup tied to the opener, listen for the context’s page event instead and verify which page was created. Do not assume that a click always produces exactly one new page; assert the expected condition for the application under test.

Model two users with separate contexts

Multi-user flows—such as checking how a chat appears to both participants—need separate session state. Create both contexts from the same browser, then a page for each participant. This keeps the test in one browser process while preventing one user’s cookies or local storage from becoming the other user’s state.

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

(async () => {
  const browser = await chromium.launch();
  const adminContext = await browser.newContext();
  const userContext = await browser.newContext();

  try {
    const adminPage = await adminContext.newPage();
    const userPage = await userContext.newPage();

    await adminPage.goto('https://example.com/admin');
    await userPage.goto('https://example.com');

    // Sign in each page using that application's own test flow.
    // Assert each user's independent view and actions here.
    console.log('Admin page:', adminPage.url());
    console.log('User page:', userPage.url());
  } finally {
    await adminContext.close();
    await userContext.close();
    await browser.close();
  }
})();

Keep authentication setup explicit: sign in separately, or use the application’s supported test fixtures or saved state for each role. Do not copy one user’s storage state into both contexts if the test is intended to prove that their sessions are isolated.

Check page state and keep cleanup reliable

Each page has its own URL, locator state, navigation, and interaction sequence. Assertions should address the page that is expected to show the result, rather than relying on whichever tab happens to be active in a human-operated browser.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Assert the expected URL after navigation or popup creation.
  • Assert an application-specific heading, status, or control on each page.
  • When order matters, await navigation or the relevant visible condition rather than adding an arbitrary delay.
  • Close each context when its scenario ends; then close the browser if the test owns it.
  • Use try/finally or the test runner’s fixture lifecycle so cleanup occurs after a failed assertion too.

Playwright recommends explicitly managing BrowserContext lifetime in production code and test frameworks. Its browser.newPage() method is a convenience for short, single-page scenarios; explicit context creation makes ownership and lifetime clearer. See Playwright Browser API and BrowserContext API.

Playwright or Puppeteer for multiple pages?

Both document pages and isolated contexts, so the central design choice is not whether one can represent multiple tabs; it is how your project handles its broader browser and test needs. The cited documentation does not establish an overall performance winner or a universal framework ranking.

  • Choose based on the browser engines your project must exercise and the framework’s current support for them.
  • Consider the programming language and how well the framework fits your existing test runner and fixtures.
  • Check popup and window behavior against the application’s real flows.
  • Evaluate the debugging and trace workflow your team needs, then account for team familiarity and existing tests.

For Puppeteer’s context guidance, see its Browser management guide. For Playwright’s object model, see its Page documentation.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Common multi-page automation problems

The popup wait times out

Check that the click really opens a browser page, that the locator targets the expected control, and that the event wait was started before the click. Some interfaces update the existing page or open a new tab through a different action; inspect the application behavior and listen for the relevant event.

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

The second page is unexpectedly signed out

Check whether you created a new context. A new context is an independent session and does not inherit the first context’s cookies or storage automatically. If it represents the same user and session, create another page inside the original context; if it represents another user, authenticate it independently.

One user appears to share another user’s state

Confirm that each user has a distinct context, not merely a distinct page. Pages in one context are part of the same session boundary.

The test hangs or leaves browser processes behind

Ensure contexts and the browser are closed on both success and failure. Put cleanup in a finally block or use the test framework’s lifecycle hooks instead of relying on the script reaching its final line.

An assertion checks the wrong tab

Keep references to the specific page objects created or received from popup events. Assert against those references and verify their URLs; do not infer page identity from tab order or focus.

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

Or skip the browser setup

If the task is to capture a website image or PDF rather than interact with several live tabs, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. A screenshot endpoint is not a substitute for browser automation that must click, authenticate, or assert state across multiple pages.

For example, this cURL request captures a screenshot of Stripe as WebP; replace the target URL as needed. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie/consent banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.
  • The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 screenshots.

Try ScreenshotNeo and sign up for 1,000 free screenshots a month with no card.

Frequently Asked Questions

Can one Playwright browser have several tabs?

Yes. A browser can have multiple page instances, with each page representing a tab or page target.

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

Does Puppeteer support isolated sessions?

Yes. Puppeteer documents browser contexts as isolated, with cookies and local storage not shared across contexts.

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.