Back to All Questions
Question 14 of 100
Core Concepts
Intermediate
What is the difference between Browser and Browser Context in Playwright?
The Answer
A `Browser` is the physical browser process (Chromium.exe). A `BrowserContext` is a lightweight isolated session within that browser (like an incognito window). Multiple contexts share one browser process but have zero shared state.
Deep Dive Explanation
The Browser β Context β Page hierarchy is what makes Playwright's multi-user testing possible. One browser process can simultaneously run tests for User A, User B, and User C β each in completely isolated contexts β without launching 3 browser processes.
example.spec.ts
// Browser is expensive to create - shared across tests in a worker
const browser = await chromium.launch(); // Launches browser process
// BrowserContext is cheap - created per test automatically
const context1 = await browser.newContext(); // User A session (own cookies/storage)
const context2 = await browser.newContext(); // User B session (completely isolated)
const context3 = await browser.newContext({ storageState: 'admin.json' }); // Admin
// Each context can have multiple pages (tabs)
const page1 = await context1.newPage();
const page2 = await context1.newPage(); // Second tab in User A's session
// Contexts are independent:
await context1.addCookies([{ name: 'session', value: 'user-a', domain: 'app.com' }]);
const cookiesInContext2 = await context2.cookies(); // [] - empty, no leakage