Playwright seems to default in incognito mode and I would like to disable this so that I can have cookies remain consistent when navigating different web pages.
I've scavenged the entire Playwright documentation and they state that a new browser context defaults to incognito but did not provide a way to disable this option.
Here is an example test that opens a non-incognito chromium window.
import { test, expect, BrowserContext, Page, chromium } from '@playwright/test';
test('test', async () => {
const browser: BrowserContext = await chromium.launchPersistentContext('', { headless: false, channel: 'chrome' });
// remove extra tab in browser window hack
const pages: Page[] = browser.pages();
const page: Page = pages[0];
await page.goto('https://www.example.com');
await expect(page.locator('div').filter({ hasText: 'example' })).toBeVisible();
});
I referenced this video: https://www.youtube.com/watch?v=-5uIFaBx738 which explains some of the details a little deeper than the Playwright documentation referenced by RoseQuartz.
You can use launchPersistentContext to create new context in normal mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With