Skip to content

Commit ce3597c

Browse files
committed
Clean up utils files
1 parent f3db4d8 commit ce3597c

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

utils.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
1313
desired_capabilities : Desired browser specs
1414
"""
1515

16-
# Create a temporary Firefox WebDriver to fetch the current user agent
17-
temp_options = webdriver.FirefoxOptions()
18-
temp_driver = webdriver.Firefox(options=temp_options)
19-
default_user_agent = temp_driver.execute_script('return navigator.userAgent;')
20-
temp_driver.quit() # Close the temporary browser instance
21-
22-
# Append "Selenium Bot" to the existing user agent
23-
custom_user_agent = f'{default_user_agent} Selenium Bot'
24-
2516
try:
2617
driver_cls = getattr(webdriver, driver_name)
2718
except AttributeError:
@@ -34,6 +25,15 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
3425
settings.BSTACK_USER, settings.BSTACK_KEY
3526
)
3627

28+
# Create a temporary Firefox WebDriver to fetch the current user agent
29+
temp_options = webdriver.FirefoxOptions()
30+
temp_driver = webdriver.Firefox(options=temp_options)
31+
default_user_agent = temp_driver.execute_script('return navigator.userAgent;')
32+
temp_driver.quit()
33+
34+
# Append "Selenium Bot" to the existing user agent
35+
custom_user_agent = f'{default_user_agent} Selenium Bot'
36+
3737
# NOTE: BrowserStack does support the use of Chrome Options, but we are not
3838
# currently using any of them. Below are several steps to setup preferences
3939
# that are specific to Firefox. Currently when running Chrome or Edge in
@@ -71,15 +71,6 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
7171
options=ffo,
7272
)
7373

74-
# get current user agent
75-
# default_user_agent = driver.execute_script("return navigator.userAgent;")
76-
77-
# Append "OSF-Selenium" to the existing user agent
78-
# custom_user_agent = f"{default_user_agent} (OSF-Selenium)"
79-
# ffo.set_preference("general.useragent.override", custom_user_agent)
80-
# driver.execute_script(f"Object.defineProperty(navigator, 'userAgent', {{get: () => '{custom_user_agent}'}});")
81-
# print(driver.execute_script("\nreturn navigator.userAgent;"))
82-
8374
elif driver_name == 'Chrome' and settings.HEADLESS:
8475
from selenium.webdriver.chrome.options import Options
8576

@@ -103,7 +94,6 @@ def launch_driver(driver_name=settings.DRIVER, desired_capabilities=None):
10394
ffo = Options()
10495
# Set the default download location [0=Desktop, 1=Downloads, 2=Specified location]
10596
ffo.set_preference('browser.download.folderList', 1)
106-
ffo.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe'
10797
ffo.set_preference('browser.download.manager.showWhenStarting', False)
10898
ffo.set_preference('browser.helperApps.alwaysAsk.force', False)
10999
ffo.set_preference(

0 commit comments

Comments
 (0)