0

I'm tying to create multiple windows of one website, so I need new identity for each. Private mode would be nice solution for me, I think. But old ways to do it doesn't give result:

firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference("browser.privatebrowsing.autostart", True)
browser = webdriver.Firefox(firefox_profile=firefox_profile)

def main():
    browser.switch_to.new_window('window')
    browser.get("https://example.com")

I couldn't find any information in docks, so maybe you can help

dimmy
  • 21
  • 7
  • Can you give a little more context around your problem please? This helps to avoid an [XY problem](https://xyproblem.info/). – James Geddes Dec 01 '21 at 16:53
  • I need to open new browser window in loop with different username and password, one account per window. My idea for now is to use private mode, but can't figure out how to use it on new version of selenium, because the old ways no longer work – dimmy Dec 01 '21 at 17:09

3 Answers3

1

As per Selenium 4 beta 1 release notes:

Deprecate all but Options and Service arguments in driver instantiation. (#9125,#9128)

So you will see an error as:

firefox_profile has been deprecated, please pass in an Options object

You have to use an instance of Options to pass the FirefoxProfile preferences as follows:

from selenium import webdriver
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.chrome.service import Service

def main():
  firefox_options = Options()
  firefox_options.set_preference("browser.privatebrowsing.autostart", True)
  s = Service('C:\\BrowserDrivers\\geckodriver.exe')
  driver = webdriver.Firefox(service=s, options=firefox_options)
  driver.get("https://www.google.com")

if __name__== "__main__" :
  main()

Browser Snapshot:

FirefoxProfile_Options


References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • How can I be sure that this is real private mode? And is it possible to adapt the code for Linux? – dimmy Dec 01 '21 at 17:30
  • I have demonstrated the way to pass the `FirefoxProfile()` _preference_ _`browser.privatebrowsing.autostart`_. But I'm not sure about the implementations as I don't use the functionality that often. – undetected Selenium Dec 01 '21 at 17:56
0

This should be the "new" way:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--incognito")

service = Service(r"C:\Program Files (x86)\chromedriver.exe")
driver = webdriver.Chrome(service=service, options=chrome_options)

It should work the same way with Firefox.

FLAK-ZOSO
  • 3,873
  • 4
  • 8
  • 28
  • It just starts normal mode. Could marionette browser mode be the reason for not being able to launch private mode? – dimmy Dec 01 '21 at 17:18
0

I figured how to make private mode for firefox:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options


def main():
    firefox_options = Options()
    firefox_options.add_argument('-private')
    driver = webdriver.Firefox(options=firefox_options)
    # driver.get("https://example.com")


if __name__ == "__main__":
    main()

I've commented line with get to make sure that browser truly opens in private mode. You can see it in tab name.

But it didn't gave me new identity for each new window as I expected.

dimmy
  • 21
  • 7