Rayrun

How do I modify my Playwright Python code to launch a normal Chrome window instead of an incognito one?

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!

References

Thank you!
Was this helpful?
Still have questions?

If you still have questions, please ask a question and I will try to answer it.

Related Discord Threads

Related Questions

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 [email protected].