Home > Software design >  Can't open chrome in incognito with Python
Can't open chrome in incognito with Python

Time:05-17

I want to open a chrome window in incognito mode with python.

I've seen others examples but always open a new tab in normal mode

import webbrowser

    browser_path = 'C:\Program Files\Google\Chrome\Application\chrome.exe --incognito %s'
    webbrowser.get(browser_path)
    webbrowser.open_new('www.google.com')

CodePudding user response:

You need to create a controller object for your browser type (in this case, chrome in incognito mode) using "get" method. Once you have the object, you can call "open_new" method. This is how I did it:

import webbrowser

browser_path = '"C:\Program Files\Google\Chrome\Application\chrome.exe" --incognito %s'
browser = webbrowser.get(browser_path) 
browser.open_new('www.google.com')
  • Related