Organize browser automation around the state that should be shared. In Playwright, use one BrowserContext for pages belonging to the same session, and a separate context for each independent test or user identity. A context contains pages; a page is a tab or page within that session. This boundary helps prevent cookies and storage from leaking between tests or actors.
What a browser context represents
In Playwright, the browser is the launched or connected browser process. A BrowserContext is an independent browser session, and a Page is a page or tab inside that session. One context can contain multiple pages. A popup opened from a page belongs to that page’s context, so it shares the session rather than starting an isolated one.
Non-persistent Playwright contexts do not write browsing data to disk. That makes them a useful default for tests that should begin without another test’s cookies or storage. The Playwright test runner creates a fresh context for each test by default and provides a page in it; when using the library directly, your code owns context creation and closure.
Choose the boundary by state, identity, and lifetime
Before deciding whether to open another tab or context, answer three questions: should the pages share browser state, do they represent the same user, and should the state survive after this run?
Free tools Windows power users keep installed
One-click scans. No signup required.
#1 Best Overall
- 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.
| Need | Playwright organization | Reason |
|---|---|---|
| Several pages for one signed-in user | Multiple pages in one context | They should share that user’s session. Popups opened from those pages also belong to the context. |
| Independent test cases | One context per test | Cookies and storage from one test should not determine another test’s result. |
| Two actors, such as admin and customer | One context per identity | The actors need separate sessions, even if the test coordinates their actions. |
| A profile that must persist between runs | A persistent context with a dedicated user-data directory | Persistent profile data has a longer lifetime than an ordinary non-persistent test context. |
Do not create a new context just because a workflow opens another tab. Create one when the workflow needs a separate state boundary. Conversely, do not put distinct actors into one context merely because they participate in the same test.
Organize Playwright tests for isolation
Use the test runner’s default isolation
For ordinary independent tests, use Playwright Test’s supplied page and context rather than keeping a global page or browser session between tests. The runner’s per-test context gives each test a clean starting environment and reduces order dependence. This matters when tests run in parallel or are sharded: a test should not rely on another test having logged in, cleared data, or run first.
Cleanup between tests can be easy to forget, and some state is difficult to remove reliably, including visited-link state. A new context is therefore generally a stronger isolation boundary than trying to reset every piece of browser state manually.
Create additional contexts for multiple identities
When a single test needs to exercise two roles, create a separate context for each role and create each role’s pages inside its own context. For example, an admin page and a customer page should not share cookies if the purpose is to verify their distinct permissions. Coordinate both pages in the test, but preserve the separate session boundary.
Rank #2
- 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.
Keep same-identity tabs together
If a flow opens a popup or navigates between related tabs as one user, keep those pages under the same context. This reflects the way the scenario uses shared session state and avoids accidentally testing two unrelated sessions instead of one multi-page workflow.
Make authentication state an explicit input
Playwright can capture storage state and use saved state when initializing a context. Treat a saved state file as an input representing a particular identity, not as generic setup shared indiscriminately across tests. A test for one account should not receive another account’s saved state. For a multi-user scenario, initialize each context with the state intended for that role.
Explicit authentication inputs also make test setup easier to reason about: the test’s identity is selected when its context is created, instead of being inherited accidentally from a prior test or a persistent local profile. Keep ownership of those state files and their use aligned with the identities they represent.
Create and close contexts explicitly with the Playwright library
When using Playwright’s library API rather than relying on the test runner fixture, the essential lifecycle is: launch a browser, create a context, create one or more pages in it, run the scenario, close the context, then close the browser. This JavaScript example shows two isolated user sessions in a single test flow:
Rank #3
- 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.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const adminContext = await browser.newContext();
const customerContext = await browser.newContext();
try {
const adminPage = await adminContext.newPage();
const customerPage = await customerContext.newPage();
await adminPage.goto('https://example.com/admin');
await customerPage.goto('https://example.com/customer');
// Perform assertions and actions for each identity here.
} finally {
await adminContext.close();
await customerContext.close();
await browser.close();
}
})();
Replace the example URLs with routes in your own application. In a real test, put assertions and any required sign-in setup in the scenario; do not assume that creating a context authenticates a user. Close contexts explicitly when the scenario is done. Playwright recommends closing contexts before the browser so artifacts such as HAR files and videos can finish flushing.
Use persistent profiles only when persistence is required
A persistent context is appropriate when the automation genuinely needs profile data to remain available across runs. Give it a dedicated user-data directory rather than pointing it at the regular Chrome user-data directory. Playwright warns that using Chrome’s main user-data directory can cause pages not to load or the browser to exit.
Keep persistent-profile workflows separate from ordinary isolated tests. A persistent profile has a different lifetime and can carry state from previous runs, so tests using it should not be treated as clean-slate tests. Use non-persistent contexts for independent work unless retaining a profile is part of the requirement.
Do not confuse Playwright contexts with WebDriver BiDi contexts
The term “browsing context” does not mean the same thing in every automation interface. In WebDriver BiDi, MDN describes a browsing context as a navigable such as a tab, iframe, or popup. BiDi also has user contexts: tabs in the same user context share browser storage, while tabs in different user contexts are isolated. Selenium’s BiDi guide covers opening tabs or windows, navigation, and inspecting context trees.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Rank #4
- 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
That terminology differs from Playwright, where BrowserContext names the independent browser session containing pages. When moving between tools, check which abstraction owns storage and session state instead of mapping names one-to-one.
Plan cleanup and concurrency ownership
Make it clear which fixture, test, or helper owns each context and is responsible for closing it. Contexts created by a test should ordinarily be closed by that test’s cleanup path, including when an assertion or navigation fails. If a context is intentionally shared across a test’s pages, close it once after those pages are no longer needed.
Playwright describes separate contexts as fast and cheap, but the documentation cited here does not establish a numeric resource cost or universal safe concurrency limit. Do not infer a concurrency cap from the fact that contexts are inexpensive. Measure the number of concurrent contexts in the target project, browser, runner, and environment; memory, application behavior, and infrastructure can differ.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Troubleshoot context organization problems
- A test sees another test’s login or cookies: check whether the tests are reusing a page or context. Give independent tests separate contexts, or use the test runner’s per-test context.
- A popup is unexpectedly signed out: verify that the workflow did not create the popup through a separate context. A popup opened by a page belongs to that page’s context.
- Admin and customer actions affect the same account: check that each actor has a separate context and that each context receives the intended authentication state.
- A test passes alone but fails in a suite: look for dependence on earlier test state, including manual cleanup that is missing or incomplete. Use a fresh context for the independent test.
- Pages fail to load or the browser exits when using a saved profile: do not point automation at Chrome’s main user-data directory. Use a dedicated directory for the persistent automation profile.
- HAR or video output is incomplete at shutdown: close explicitly created contexts before closing the browser so context artifacts can finish flushing.
- Parallel runs fail intermittently: first remove state-sharing and ordering assumptions. Then measure concurrency in the actual runner and environment; there is no universal numeric cap established here.
Or skip the browser setup
If the task is to capture a website screenshot rather than automate a multi-page session, ScreenshotNeo provides a one-request screenshot API; it is not a replacement for organizing Playwright contexts when your workflow needs interactive browser state. For example, save a screenshot as WebP with cURL:
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Best Value
- 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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for request options. It accepts consent banners like a visitor and removes known consent platforms, newsletter popups, and chat widgets before capture; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
Frequently Asked Questions
Does a Playwright page have its own cookies?
Cookies and browser storage belong to its context, so pages in the same context share that session state.
Should I use a new context for every tab?
No. Put tabs that belong to the same user session in one context; use separate contexts for independent sessions or identities.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitchesCan WebDriver BiDi browsing contexts be treated as Playwright BrowserContexts?
No. BiDi distinguishes browsing contexts from user contexts, and the storage-sharing boundary is associated with the user context.
Quick Recap
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.

