Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playwright/Context: Is there a way to create a browser context in a normal state and not in incognito?

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.

like image 894
dracoDevs Avatar asked Oct 23 '25 16:10

dracoDevs


2 Answers

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.

like image 194
Georg3.14159265 Avatar answered Oct 26 '25 18:10

Georg3.14159265


You can use launchPersistentContext to create new context in normal mode

like image 25
RoseQuartz Avatar answered Oct 26 '25 18:10

RoseQuartz