19 March 2022

How to open an URL in Chrome incognito mode using Python?

You may refer to the sample codes below from us. We use Windows platform as an example:


import webbrowser

def main():
    fUrl: str = 'https://prgexp.blogspot.com/'

    chrome_path = 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe'
    webbrowser.register('chrome', None, webbrowser.BackgroundBrowser(chrome_path))
    webbrowser.get('chrome').args.append('--incognito')
    webbrowser.get('chrome').open_new_tab(fUrl)

if __name__ == '__main__':
    main()

No comments: