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?"
Use persistent context, https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch-persistent-context
Related Ask AI answer for "How do I modify my Playwright Python code to launch a normal Chrome window instead of an incognito one?".
By default, Playwright launches browsers in incognito mode. But don't worry, you can easily change this behavior.
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!
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 [email protected].