1

Using webbrowser module and webbrowser.open method, we can open URL in new tab. However, is there any way we can open a secret tab in Google by using Python?

import webbrowser

webbrowser.open_new("http://google.com")
martineau
  • 119,623
  • 25
  • 170
  • 301
Constant
  • 29
  • 5
  • 2
    What's a "secret tab"? Do you mean private/incognito mode? – Random Davis Nov 10 '20 at 16:33
  • A [secret tab](https://www.google.com/search?q=what+is+a+chrome+secret+tab&rlz=1C1OKWM_enUS773US773&oq=what+is+a+chrome+secret+tab&aqs=chrome..69i57.4722j0j1&sourceid=chrome&ie=UTF-8) is an incognito tab. – Lakshya Raj Nov 10 '20 at 16:35
  • 1
    @LakshyaRaj except that it's not called a Secret Tab – SiHa Nov 10 '20 at 16:41
  • @SiHa : True but I guess for this type of thing, we have to understand :) – Lakshya Raj Nov 10 '20 at 16:45
  • Are you sure that "webbrowser.open_new()" will open Chrome? What happens if my default browser is Firefox? Or a browser that does not allow "incognito" mode? – Be Chiller Too Nov 10 '20 at 16:47

2 Answers2

2

You'd be better off using os.system() to launch chrome with incognito argument.

Example: os.system("C:\path\to\chrome\executable.exe -ArgumentList @( '-incognito','https://www.google.com'")

Nastor
  • 638
  • 4
  • 15
2

It is possible to use the method you are using to open a 'secret tab'. Try this:

webbrowser.get("C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s --incognito")
.open("<URL YOU WANT TO OPEN>")

The special part is --incognito. It signifies incognito mode (to open a secret/incognito tab). %s is used to signify the URL to open (specified by the .open function). A side note: you can NOT replace %s with your URL, or else it raises webbrowser.Error.

Lakshya Raj
  • 1,669
  • 3
  • 10
  • 34