Skip to content

Commit db5c22b

Browse files
authored
Merge pull request #1423 from seleniumbase/update-firefox-preferences
Update Default Firefox Preferences
2 parents 5f26c1f + 75c8ea6 commit db5c22b

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta property="og:image" content="https://seleniumbase.io/cdn/img/mac_sb_logo_5b.png" />
66
<link rel="icon" href="https://seleniumbase.io/img/green_logo2.png" />
77

8-
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/sb_logo_gs9.png" alt="SeleniumBase" title="SeleniumBase" width="280" /></a></p>
8+
<p align="center"><a href="https://github.com/seleniumbase/SeleniumBase/"><img src="https://seleniumbase.io/cdn/img/sb_logo_gs4.png" alt="SeleniumBase" title="SeleniumBase" width="420" /></a></p>
99
<p align="center"><b>Scale your Web UI testing with <a href="https://www.selenium.dev/documentation/">Selenium</a>, <a href="https://www.python.org/about/">Python</a>, and <a href="https://docs.pytest.org/en/latest/how-to/usage.html">pytest</a>.</b></p>
1010

1111
<p align="center"><a href="https://pypi.python.org/pypi/seleniumbase" target="_blank"><img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=3399EE" alt="PyPI version" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/releases" target="_blank"><img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=22AAEE" alt="GitHub version" /></a> <a href="https://seleniumbase.io"><img src="https://img.shields.io/badge/docs-seleniumbase.io-11BBAA.svg" alt="SeleniumBase Docs" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions" target="_blank"><img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg" alt="SeleniumBase GitHub Actions" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase" target="_blank"><img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="SeleniumBase" /></a></p>
@@ -83,9 +83,9 @@ pytest test_demo_site.py --chrome
8383

8484
<h4>Here's a 2FA/MFA app that can be tested with SeleniumBase:</h4>
8585

86-
<p align="left"><a href="https://seleniumbase.io/realworld/login" target="_blank"><img src="https://seleniumbase.io/cdn/img/mfa_login_s.png" width="330" alt="SeleniumBase MFA Demo App" title="SeleniumBase MFA Demo App" /></a></p>
86+
<p align="left"><a href="https://seleniumbase.io/realworld/login" target="_blank"><img src="https://seleniumbase.io/cdn/img/mfa_login_s.png" width="290" alt="SeleniumBase MFA Demo App" title="SeleniumBase MFA Demo App" /></a></p>
8787

88-
<h4>Here are a few ways of testing that app with SeleniumBase:</h4>
88+
<h4>Here are a few scripts to test that app with SeleniumBase:</h4>
8989

9090
<p align="left">📘📝 An example test with the <b>BaseCase</b> class. Runs with <code>pytest</code> or <code>nosetests</code>. (<a href="https://github.com/seleniumbase/SeleniumBase/blob/master/examples/ReadMe.md">Learn more</a>)</p>
9191

seleniumbase/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "3.5.6"
2+
__version__ = "3.5.7"

seleniumbase/core/browser_launcher.py

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ def _set_firefox_options(
533533
options.set_preference("browser.startup.homepage", blank_p)
534534
options.set_preference("startup.homepage_welcome_url", blank_p)
535535
options.set_preference("startup.homepage_welcome_url.additional", blank_p)
536+
options.set_preference("browser.newtab.url", blank_p)
536537
options.set_preference("trailhead.firstrun.branches", "nofirstrun-empty")
537538
options.set_preference("browser.aboutwelcome.enabled", False)
538539
options.set_preference("pdfjs.disabled", True)
@@ -551,7 +552,11 @@ def _set_firefox_options(
551552
options.set_preference("datareporting.healthreport.service.enabled", False)
552553
options.set_preference("datareporting.healthreport.uploadEnabled", False)
553554
options.set_preference("datareporting.policy.dataSubmissionEnabled", False)
555+
options.set_preference("browser.search.update", False)
556+
options.set_preference("privacy.trackingprotection.enabled", False)
557+
options.set_preference("toolkit.telemetry.enabled", False)
554558
options.set_preference("toolkit.telemetry.unified", False)
559+
options.set_preference("toolkit.telemetry.archive.enabled", False)
555560
if proxy_string:
556561
socks_proxy = False
557562
socks_ver = 0
@@ -588,6 +593,7 @@ def _set_firefox_options(
588593
options.set_preference(
589594
"security.mixed_content.block_active_content", False
590595
)
596+
options.set_preference("security.warn_submit_insecure", False)
591597
if settings.DISABLE_CSP_ON_FIREFOX or disable_csp:
592598
options.set_preference("security.csp.enable", False)
593599
options.set_preference(
@@ -1503,18 +1509,23 @@ def get_local_driver(
15031509
if selenium4:
15041510
service = FirefoxService(
15051511
executable_path=LOCAL_GECKODRIVER,
1506-
log_path=os.path.devnull,
1512+
log_path=os.devnull,
15071513
)
15081514
try:
15091515
return webdriver.Firefox(
15101516
service=service,
15111517
options=firefox_options,
15121518
)
1513-
except Exception as e:
1519+
except BaseException as e:
15141520
if (
1515-
"Process unexpectedly closed" in e.msg
1516-
or "Failed to read marionette port" in e.msg
1517-
or "A connection attempt failed" in e.msg
1521+
"Process unexpectedly closed" in str(e)
1522+
or "Failed to read marionette port" in str(e)
1523+
or "A connection attempt failed" in str(e)
1524+
or hasattr(e, "msg") and (
1525+
"Process unexpectedly closed" in e.msg
1526+
or "Failed to read marionette port" in e.msg
1527+
or "A connection attempt failed" in e.msg
1528+
)
15181529
):
15191530
# Firefox probably just auto-updated itself.
15201531
# Trying again right after that often works.
@@ -1523,25 +1534,30 @@ def get_local_driver(
15231534
options=firefox_options,
15241535
)
15251536
else:
1526-
raise Exception(e.msg) # Not an obvious fix.
1537+
raise # Not an obvious fix.
15271538
else:
15281539
return webdriver.Firefox(
15291540
executable_path=LOCAL_GECKODRIVER,
1530-
service_log_path=os.path.devnull,
1541+
service_log_path=os.devnull,
15311542
options=firefox_options,
15321543
)
15331544
else:
15341545
if selenium4:
1535-
service = FirefoxService(log_path=os.path.devnull)
1546+
service = FirefoxService(log_path=os.devnull)
15361547
try:
15371548
return webdriver.Firefox(
15381549
service=service, options=firefox_options
15391550
)
1540-
except Exception as e:
1551+
except BaseException as e:
15411552
if (
1542-
"Process unexpectedly closed" in e.msg
1543-
or "Failed to read marionette port" in e.msg
1544-
or "A connection attempt failed" in e.msg
1553+
"Process unexpectedly closed" in str(e)
1554+
or "Failed to read marionette port" in str(e)
1555+
or "A connection attempt failed" in str(e)
1556+
or hasattr(e, "msg") and (
1557+
"Process unexpectedly closed" in e.msg
1558+
or "Failed to read marionette port" in e.msg
1559+
or "A connection attempt failed" in e.msg
1560+
)
15451561
):
15461562
# Firefox probably just auto-updated itself.
15471563
# Trying again right after that often works.
@@ -1550,10 +1566,10 @@ def get_local_driver(
15501566
options=firefox_options,
15511567
)
15521568
else:
1553-
raise Exception(e.msg) # Not an obvious fix.
1569+
raise # Not an obvious fix.
15541570
else:
15551571
return webdriver.Firefox(
1556-
service_log_path=os.path.devnull,
1572+
service_log_path=os.devnull,
15571573
options=firefox_options,
15581574
)
15591575
elif browser_name == constants.Browser.INTERNET_EXPLORER:
@@ -1820,7 +1836,7 @@ def get_local_driver(
18201836
if selenium4:
18211837
try:
18221838
service = EdgeService(
1823-
executable_path=LOCAL_EDGEDRIVER, log_path=os.path.devnull
1839+
executable_path=LOCAL_EDGEDRIVER, log_path=os.devnull
18241840
)
18251841
driver = Edge(service=service, options=edge_options)
18261842
except Exception as e:
@@ -1840,13 +1856,13 @@ def get_local_driver(
18401856
elif "DevToolsActivePort file doesn't exist" in e.msg:
18411857
service = EdgeService(
18421858
executable_path=LOCAL_EDGEDRIVER,
1843-
log_path=os.path.devnull,
1859+
log_path=os.devnull,
18441860
)
18451861
# https://stackoverflow.com/a/56638103/7058266
18461862
edge_options.add_argument("--remote-debugging-port=9222")
18471863
return Edge(service=service, options=edge_options)
18481864
if not auto_upgrade_edgedriver:
1849-
raise Exception(e.msg) # Not an obvious fix. Raise.
1865+
raise # Not an obvious fix.
18501866
else:
18511867
pass # Try upgrading EdgeDriver to match Edge.
18521868
args = " ".join(sys.argv)
@@ -1865,7 +1881,7 @@ def get_local_driver(
18651881
_repair_edgedriver(edge_version)
18661882
_mark_driver_repaired()
18671883
service = EdgeService(
1868-
executable_path=LOCAL_EDGEDRIVER, log_path=os.path.devnull
1884+
executable_path=LOCAL_EDGEDRIVER, log_path=os.devnull
18691885
)
18701886
driver = Edge(service=service, options=edge_options)
18711887
return driver
@@ -1875,7 +1891,7 @@ def get_local_driver(
18751891
try:
18761892
driver = Edge(
18771893
executable_path=LOCAL_EDGEDRIVER,
1878-
service_log_path=os.path.devnull,
1894+
service_log_path=os.devnull,
18791895
capabilities=capabilities,
18801896
)
18811897
except Exception as e:
@@ -1895,13 +1911,13 @@ def get_local_driver(
18951911
elif "DevToolsActivePort file doesn't exist" in e.msg:
18961912
service = EdgeService(
18971913
executable_path=LOCAL_EDGEDRIVER,
1898-
log_path=os.path.devnull,
1914+
log_path=os.devnull,
18991915
)
19001916
# https://stackoverflow.com/a/56638103/7058266
19011917
edge_options.add_argument("--remote-debugging-port=9222")
19021918
return Edge(service=service, options=edge_options)
19031919
if not auto_upgrade_edgedriver:
1904-
raise Exception(e.msg) # Not an obvious fix. Raise.
1920+
raise # Not an obvious fix.
19051921
else:
19061922
pass # Try upgrading EdgeDriver to match Edge.
19071923
args = " ".join(sys.argv)
@@ -1921,7 +1937,7 @@ def get_local_driver(
19211937
_mark_driver_repaired()
19221938
driver = Edge(
19231939
executable_path=LOCAL_EDGEDRIVER,
1924-
service_log_path=os.path.devnull,
1940+
service_log_path=os.devnull,
19251941
capabilities=capabilities,
19261942
)
19271943
return driver
@@ -2076,7 +2092,7 @@ def get_local_driver(
20762092
if selenium4:
20772093
service = ChromeService(
20782094
executable_path=LOCAL_CHROMEDRIVER,
2079-
log_path=os.path.devnull,
2095+
log_path=os.devnull,
20802096
)
20812097
driver = webdriver.Chrome(
20822098
service=service,
@@ -2085,19 +2101,19 @@ def get_local_driver(
20852101
else:
20862102
driver = webdriver.Chrome(
20872103
executable_path=LOCAL_CHROMEDRIVER,
2088-
service_log_path=os.path.devnull,
2104+
service_log_path=os.devnull,
20892105
options=chrome_options,
20902106
)
20912107
else:
20922108
if selenium4:
2093-
service = ChromeService(log_path=os.path.devnull)
2109+
service = ChromeService(log_path=os.devnull)
20942110
driver = webdriver.Chrome(
20952111
service=service, options=chrome_options
20962112
)
20972113
else:
20982114
driver = webdriver.Chrome(
20992115
options=chrome_options,
2100-
service_log_path=os.path.devnull,
2116+
service_log_path=os.devnull,
21012117
)
21022118
except Exception as e:
21032119
auto_upgrade_chromedriver = False
@@ -2106,7 +2122,7 @@ def get_local_driver(
21062122
elif "Chrome version must be between" in e.msg:
21072123
auto_upgrade_chromedriver = True
21082124
if not auto_upgrade_chromedriver:
2109-
raise Exception(e.msg) # Not an obvious fix. Raise.
2125+
raise # Not an obvious fix.
21102126
else:
21112127
pass # Try upgrading ChromeDriver to match Chrome.
21122128
mcv = None # Major Chrome Version
@@ -2251,14 +2267,14 @@ def get_local_driver(
22512267
)
22522268
chrome_options.headless = False
22532269
return webdriver.Chrome(options=chrome_options)
2254-
except Exception as e:
2270+
except Exception:
22552271
try:
22562272
# Try again if Chrome didn't launch
22572273
return webdriver.Chrome(options=chrome_options)
22582274
except Exception:
22592275
pass
22602276
if headless:
2261-
raise Exception(e)
2277+
raise
22622278
if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
22632279
try:
22642280
make_driver_executable_if_not(LOCAL_CHROMEDRIVER)

0 commit comments

Comments
 (0)