Skip to content

Commit 5a90a60

Browse files
committed
Perform Firefox optimizations
1 parent cd13931 commit 5a90a60

File tree

1 file changed

+39
-48
lines changed

1 file changed

+39
-48
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -523,9 +523,15 @@ def _set_firefox_options(
523523
firefox_arg,
524524
firefox_pref,
525525
):
526+
blank_p = "about:blank"
526527
options = webdriver.FirefoxOptions()
527528
options.accept_untrusted_certs = True
528529
options.set_preference("reader.parse-on-load.enabled", False)
530+
options.set_preference("browser.startup.homepage", blank_p)
531+
options.set_preference("startup.homepage_welcome_url", blank_p)
532+
options.set_preference("startup.homepage_welcome_url.additional", blank_p)
533+
options.set_preference("trailhead.firstrun.branches", "nofirstrun-empty")
534+
options.set_preference("browser.aboutwelcome.enabled", False)
529535
options.set_preference("pdfjs.disabled", True)
530536
options.set_preference("app.update.auto", False)
531537
options.set_preference("app.update.enabled", False)
@@ -1485,60 +1491,45 @@ def get_local_driver(
14851491
)
14861492
sb_install.main(override="geckodriver")
14871493
sys.argv = sys_args # Put back original sys args
1488-
warnings.simplefilter("ignore", category=DeprecationWarning)
1489-
if "linux" in PLATFORM:
1490-
from selenium.webdriver.common.desired_capabilities import (
1491-
DesiredCapabilities,
1492-
)
1493-
1494-
firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
1495-
firefox_capabilities["marionette"] = True
1496-
if headless:
1497-
firefox_capabilities["moz:firefoxOptions"] = {
1498-
"args": ["-headless"]
1499-
}
1500-
return webdriver.Firefox(
1501-
capabilities=firefox_capabilities, options=firefox_options
1502-
)
1503-
else:
1504-
if os.path.exists(LOCAL_GECKODRIVER):
1505-
if selenium4:
1506-
service = FirefoxService(
1507-
executable_path=LOCAL_GECKODRIVER,
1508-
log_path=os.path.devnull,
1494+
# Launch Firefox
1495+
if os.path.exists(LOCAL_GECKODRIVER):
1496+
if selenium4:
1497+
service = FirefoxService(
1498+
executable_path=LOCAL_GECKODRIVER,
1499+
log_path=os.path.devnull,
1500+
)
1501+
try:
1502+
return webdriver.Firefox(
1503+
service=service,
1504+
options=firefox_options,
15091505
)
1510-
try:
1506+
except Exception as e:
1507+
if "Process unexpectedly closed" in e.msg:
1508+
# Firefox probably just auto-updated itself.
1509+
# Trying again right after that often works.
15111510
return webdriver.Firefox(
15121511
service=service,
15131512
options=firefox_options,
15141513
)
1515-
except Exception as e:
1516-
if "Process unexpectedly closed" in e.msg:
1517-
# Firefox probably just auto-updated itself.
1518-
# Trying again right after that often works.
1519-
return webdriver.Firefox(
1520-
service=service,
1521-
options=firefox_options,
1522-
)
1523-
else:
1524-
raise Exception(e.msg) # Not an obvious fix.
1525-
else:
1526-
return webdriver.Firefox(
1527-
executable_path=LOCAL_GECKODRIVER,
1528-
service_log_path=os.path.devnull,
1529-
options=firefox_options,
1530-
)
1514+
else:
1515+
raise Exception(e.msg) # Not an obvious fix.
15311516
else:
1532-
if selenium4:
1533-
service = FirefoxService(log_path=os.path.devnull)
1534-
return webdriver.Firefox(
1535-
service=service, options=firefox_options
1536-
)
1537-
else:
1538-
return webdriver.Firefox(
1539-
service_log_path=os.path.devnull,
1540-
options=firefox_options,
1541-
)
1517+
return webdriver.Firefox(
1518+
executable_path=LOCAL_GECKODRIVER,
1519+
service_log_path=os.path.devnull,
1520+
options=firefox_options,
1521+
)
1522+
else:
1523+
if selenium4:
1524+
service = FirefoxService(log_path=os.path.devnull)
1525+
return webdriver.Firefox(
1526+
service=service, options=firefox_options
1527+
)
1528+
else:
1529+
return webdriver.Firefox(
1530+
service_log_path=os.path.devnull,
1531+
options=firefox_options,
1532+
)
15421533
elif browser_name == constants.Browser.INTERNET_EXPLORER:
15431534
if not IS_WINDOWS:
15441535
raise Exception(

0 commit comments

Comments
 (0)