Rayrun
← Back to Discord Forum

Opens in incognito mode.

my playwright python code always opens in incognito window. how can i fix it to open in normal window of chrome?

This thread is trying to answer question "How can I fix my Playwright Python code to open in a normal window of Chrome instead of incognito window?"

2 replies

Opening incognito like sessions is default behavior for Playwright to make a fresh and clean environkent for each test

Answer

Launching a Normal Chrome Window with Playwright

By default, Playwright launches browsers in incognito mode. But don't worry, you can easily change this behavior.

Modify the Launch Function

You need to tweak the launch function from the Playwright library. Specifically, set the headless option to False to launch Chrome in non-headless mode. This makes the browser window visible on your screen. Also, set the args option with "--incognito" to explicitly disable incognito mode.

Here's how you can do it:

const { chromium } = require('@playwright/test');

async function openNormalChromeWindow() {
  const browser = await chromium.launch({
    headless: false,
    args: ['--incognito']
  });

  const context = await browser.newContext();

  // Your code for interacting with the page goes here

  await browser.close();
}

openNormalChromeWindow();

In this code, chromium.launch() launches a new Chromium instance with non-headless mode and incognito mode disabled. Then, browser.newContext() creates a new context. You can perform any necessary actions on the page within this context. Finally, browser.close() closes the browser.

By following these steps, you can easily modify your Playwright Python code to open a normal Chrome window. Happy testing with Playwright!

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.