Skip to main content

BrowserContext

BrowserContexts provide a way to operate multiple independent browser sessions.

If a page opens another page, e.g. with a window.open call, the popup will belong to the parent page's browser context.

Playwright allows creating isolated non-persistent browser contexts with browser.newContext() method. Non-persistent browser contexts don't write any browsing data to disk.

// Create a new incognito browser context
const context = await browser.newContext();
// Create a new page inside context.
const page = await context.newPage();
await page.goto('https://example.com');
// Dispose context once it's no longer needed.
await context.close();

Methods​

addCookies​

Added before v1.9 browserContext.addCookies

Adds cookies into this browser context. All pages within this context will have these cookies installed. Cookies can be obtained via browserContext.cookies().

Usage

await browserContext.addCookies([cookieObject1, cookieObject2