A browser context is an isolated session — like an incognito window — with its own cookies, storage, and permissions. Playwright creates one per test by default.
What Is a Browser Context?
Browser → Context → Page is the hierarchy. One browser process can host multiple contexts that do not share cookies or localStorage. Each test typically gets a fresh context via the context and page fixtures.
Contexts let you simulate two users in one test: create two contexts, two pages, and interact independently — useful for chat, collaboration, or admin vs regular user scenarios.
test('admin and user sessions', async ({ browser }) => {
const adminContext = await browser.newContext();
const userContext = await browser.newContext();
const adminPage = await adminContext.newPage();
const userPage = await userContext.newPage();
// each page has separate cookies/storage
});
Use browser fixture when you need multiple contexts in one test.
storageState restores saved cookies and localStorage.
permissions grants camera, geolocation, etc.
locale and timezoneId affect Intl and Date formatting.
viewport and isMobile emulate device characteristics.
Browser Context Cheat Sheet
Common context configuration options.
Option
Purpose
storageState
Reuse authenticated session
baseURL
Default origin for page.goto('/path')
ignoreHTTPSErrors
Accept self-signed certs in dev
recordVideo
Capture video for this context
serviceWorkers
Allow/block service workers
colorScheme
light, dark, or no-preference
Default Isolation in the Test Runner
The test runner creates a new context for each test automatically. You rarely call newContext() unless testing multi-user flows or customizing options per test via test.use().