seleniumbase 4.30.8__py3-none-any.whl → 4.31.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. sbase/__init__.py +1 -0
  2. seleniumbase/__init__.py +2 -3
  3. seleniumbase/__version__.py +1 -1
  4. seleniumbase/behave/behave_sb.py +59 -11
  5. seleniumbase/config/settings.py +4 -0
  6. seleniumbase/console_scripts/logo_helper.py +47 -0
  7. seleniumbase/console_scripts/run.py +7 -4
  8. seleniumbase/console_scripts/sb_behave_gui.py +5 -5
  9. seleniumbase/console_scripts/sb_caseplans.py +6 -6
  10. seleniumbase/console_scripts/sb_commander.py +5 -5
  11. seleniumbase/console_scripts/sb_install.py +10 -2
  12. seleniumbase/console_scripts/sb_recorder.py +4 -4
  13. seleniumbase/core/browser_launcher.py +179 -108
  14. seleniumbase/core/mysql.py +1 -4
  15. seleniumbase/core/recorder_helper.py +24 -5
  16. seleniumbase/core/sb_driver.py +13 -3
  17. seleniumbase/core/settings_parser.py +4 -0
  18. seleniumbase/fixtures/base_case.py +324 -493
  19. seleniumbase/fixtures/js_utils.py +19 -52
  20. seleniumbase/fixtures/page_actions.py +3 -6
  21. seleniumbase/fixtures/page_utils.py +18 -53
  22. seleniumbase/plugins/base_plugin.py +2 -3
  23. seleniumbase/plugins/driver_manager.py +182 -5
  24. seleniumbase/plugins/pytest_plugin.py +51 -23
  25. seleniumbase/plugins/sb_manager.py +185 -5
  26. seleniumbase/plugins/selenium_plugin.py +71 -8
  27. seleniumbase/undetected/__init__.py +13 -38
  28. seleniumbase/undetected/dprocess.py +4 -6
  29. seleniumbase/undetected/options.py +3 -6
  30. seleniumbase/undetected/patcher.py +2 -3
  31. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/METADATA +111 -125
  32. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/RECORD +36 -47
  33. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/WHEEL +1 -1
  34. sbase/ReadMe.txt +0 -2
  35. seleniumbase/ReadMe.md +0 -25
  36. seleniumbase/common/ReadMe.md +0 -71
  37. seleniumbase/console_scripts/ReadMe.md +0 -734
  38. seleniumbase/drivers/ReadMe.md +0 -27
  39. seleniumbase/extensions/ReadMe.md +0 -12
  40. seleniumbase/masterqa/ReadMe.md +0 -61
  41. seleniumbase/resources/ReadMe.md +0 -31
  42. seleniumbase/resources/favicon.ico +0 -0
  43. seleniumbase/utilities/selenium_grid/ReadMe.md +0 -84
  44. seleniumbase/utilities/selenium_ide/ReadMe.md +0 -111
  45. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/LICENSE +0 -0
  46. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/entry_points.txt +0 -0
  47. {seleniumbase-4.30.8.dist-info → seleniumbase-4.31.1.dist-info}/top_level.txt +0 -0
@@ -9,6 +9,7 @@ import time
9
9
  import types
10
10
  import urllib3
11
11
  import warnings
12
+ from contextlib import suppress
12
13
  from selenium import webdriver
13
14
  from selenium.common.exceptions import ElementClickInterceptedException
14
15
  from selenium.common.exceptions import InvalidSessionIdException
@@ -202,6 +203,8 @@ def extend_driver(driver):
202
203
  driver.is_exact_text_visible = DM.is_exact_text_visible
203
204
  driver.is_attribute_present = DM.is_attribute_present
204
205
  driver.is_non_empty_text_visible = DM.is_non_empty_text_visible
206
+ driver.is_valid_url = DM.is_valid_url
207
+ driver.is_alert_present = DM.is_alert_present
205
208
  driver.is_online = DM.is_online
206
209
  driver.js_click = DM.js_click
207
210
  driver.get_text = DM.get_text
@@ -277,7 +280,7 @@ def chromedriver_on_path():
277
280
  def get_uc_driver_version(full=False):
278
281
  uc_driver_version = None
279
282
  if os.path.exists(LOCAL_UC_DRIVER):
280
- try:
283
+ with suppress(Exception):
281
284
  output = subprocess.check_output(
282
285
  '"%s" --version' % LOCAL_UC_DRIVER, shell=True
283
286
  )
@@ -292,8 +295,6 @@ def get_uc_driver_version(full=False):
292
295
  uc_driver_version = full_version
293
296
  else:
294
297
  uc_driver_version = output
295
- except Exception:
296
- pass
297
298
  return uc_driver_version
298
299
 
299
300
 
@@ -372,7 +373,7 @@ def uc_special_open_if_cf(
372
373
  ):
373
374
  if url.startswith("http:") or url.startswith("https:"):
374
375
  special = False
375
- try:
376
+ with suppress(Exception):
376
377
  req_get = requests_get(url, proxy_string)
377
378
  status_str = str(req_get.status_code)
378
379
  if (
@@ -384,8 +385,6 @@ def uc_special_open_if_cf(
384
385
  special = True
385
386
  if status_str == "403" or status_str == "429":
386
387
  time.sleep(0.06) # Forbidden / Blocked! (Wait first!)
387
- except Exception:
388
- pass
389
388
  if special:
390
389
  time.sleep(0.05)
391
390
  with driver:
@@ -416,13 +415,11 @@ def uc_special_open_if_cf(
416
415
  "mobile": True
417
416
  }
418
417
  )
419
- try:
418
+ with suppress(Exception):
420
419
  driver.execute_cdp_cmd(
421
420
  'Emulation.setDeviceMetricsOverride',
422
421
  set_device_metrics_override
423
422
  )
424
- except Exception:
425
- pass
426
423
  if not mobile_emulator:
427
424
  page_actions.switch_to_window(
428
425
  driver, driver.window_handles[-1], 2
@@ -529,13 +526,11 @@ def uc_click(
529
526
  timeout=settings.SMALL_TIMEOUT,
530
527
  reconnect_time=None,
531
528
  ):
532
- try:
529
+ with suppress(Exception):
533
530
  rct = float(by) # Add shortcut: driver.uc_click(selector, RCT)
534
531
  if not reconnect_time:
535
532
  reconnect_time = rct
536
533
  by = "css selector"
537
- except Exception:
538
- pass
539
534
  element = driver.wait_for_selector(selector, by=by, timeout=timeout)
540
535
  tag_name = element.tag_name
541
536
  if not tag_name == "span" and not tag_name == "input": # Must be "visible"
@@ -574,7 +569,7 @@ def install_pyautogui_if_missing(driver):
574
569
  with pip_find_lock: # Prevent issues with multiple processes
575
570
  try:
576
571
  import pyautogui
577
- try:
572
+ with suppress(Exception):
578
573
  use_pyautogui_ver = constants.PyAutoGUI.VER
579
574
  if pyautogui.__version__ != use_pyautogui_ver:
580
575
  del pyautogui
@@ -582,8 +577,6 @@ def install_pyautogui_if_missing(driver):
582
577
  "pyautogui", version=use_pyautogui_ver
583
578
  )
584
579
  import pyautogui
585
- except Exception:
586
- pass
587
580
  except Exception:
588
581
  print("\nPyAutoGUI required! Installing now...")
589
582
  shared_utils.pip_install(
@@ -602,16 +595,32 @@ def install_pyautogui_if_missing(driver):
602
595
  and not (sb_config.headless or sb_config.headless2)
603
596
  ):
604
597
  from sbvirtualdisplay import Display
605
- try:
598
+ xvfb_width = 1366
599
+ xvfb_height = 768
600
+ if (
601
+ hasattr(sb_config, "_xvfb_width")
602
+ and sb_config._xvfb_width
603
+ and isinstance(sb_config._xvfb_width, int)
604
+ and hasattr(sb_config, "_xvfb_height")
605
+ and sb_config._xvfb_height
606
+ and isinstance(sb_config._xvfb_height, int)
607
+ ):
608
+ xvfb_width = sb_config._xvfb_width
609
+ xvfb_height = sb_config._xvfb_height
610
+ if xvfb_width < 1024:
611
+ xvfb_width = 1024
612
+ sb_config._xvfb_width = xvfb_width
613
+ if xvfb_height < 768:
614
+ xvfb_height = 768
615
+ sb_config._xvfb_height = xvfb_height
616
+ with suppress(Exception):
606
617
  xvfb_display = Display(
607
618
  visible=True,
608
- size=(1366, 768),
619
+ size=(xvfb_width, xvfb_height),
609
620
  backend="xvfb",
610
621
  use_xauth=True,
611
622
  )
612
623
  xvfb_display.start()
613
- except Exception:
614
- pass
615
624
 
616
625
 
617
626
  def get_configured_pyautogui(pyautogui_copy):
@@ -778,12 +787,10 @@ def uc_gui_click_x_y(driver, x, y, timeframe=0.25):
778
787
  y = y * width_ratio
779
788
  _uc_gui_click_x_y(driver, x, y, timeframe=timeframe, uc_lock=False)
780
789
  return
781
- try:
790
+ with suppress(Exception):
782
791
  page_actions.switch_to_window(
783
792
  driver, driver.current_window_handle, 2, uc_lock=False
784
793
  )
785
- except Exception:
786
- pass
787
794
  _uc_gui_click_x_y(driver, x, y, timeframe=timeframe, uc_lock=False)
788
795
 
789
796
 
@@ -986,10 +993,8 @@ def _uc_gui_click_captcha(
986
993
  driver.uc_open_with_disconnect(driver.current_url, 3.8)
987
994
  else:
988
995
  driver.disconnect()
989
- try:
990
- _uc_gui_click_x_y(driver, x, y, timeframe=0.54321)
991
- except Exception:
992
- pass
996
+ with suppress(Exception):
997
+ _uc_gui_click_x_y(driver, x, y, timeframe=0.32)
993
998
  reconnect_time = (float(constants.UC.RECONNECT_TIME) / 2.0) + 0.6
994
999
  if IS_LINUX:
995
1000
  reconnect_time = constants.UC.RECONNECT_TIME + 0.2
@@ -1031,12 +1036,12 @@ def _uc_gui_click_captcha(
1031
1036
  return
1032
1037
  if blind:
1033
1038
  driver.uc_open_with_disconnect(driver.current_url, 3.8)
1034
- _uc_gui_click_x_y(driver, x, y, timeframe=1.05)
1039
+ _uc_gui_click_x_y(driver, x, y, timeframe=0.32)
1035
1040
  else:
1036
1041
  driver.uc_open_with_reconnect(driver.current_url, 3.8)
1037
1042
  if _on_a_captcha_page(driver):
1038
1043
  driver.disconnect()
1039
- _uc_gui_click_x_y(driver, x, y, timeframe=1.05)
1044
+ _uc_gui_click_x_y(driver, x, y, timeframe=0.32)
1040
1045
  driver.reconnect(reconnect_time)
1041
1046
 
1042
1047
 
@@ -1216,13 +1221,11 @@ def _uc_gui_handle_captcha_(driver, frame="iframe", ctype=None):
1216
1221
  and sb_config._saved_cf_tab_count
1217
1222
  ):
1218
1223
  driver.uc_open_with_disconnect(driver.current_url, 3.8)
1219
- try:
1224
+ with suppress(Exception):
1220
1225
  for i in range(sb_config._saved_cf_tab_count):
1221
1226
  pyautogui.press("\t")
1222
1227
  time.sleep(0.027)
1223
1228
  pyautogui.press(" ")
1224
- except Exception:
1225
- pass
1226
1229
  else:
1227
1230
  driver.disconnect()
1228
1231
  pyautogui.press(" ")
@@ -1552,6 +1555,7 @@ def _set_chrome_options(
1552
1555
  log_cdp_events,
1553
1556
  no_sandbox,
1554
1557
  disable_gpu,
1558
+ headless1,
1555
1559
  headless2,
1556
1560
  incognito,
1557
1561
  guest_mode,
@@ -1669,18 +1673,49 @@ def _set_chrome_options(
1669
1673
  chrome_options.add_experimental_option(
1670
1674
  "mobileEmulation", emulator_settings
1671
1675
  )
1676
+ # Handle Window Position
1677
+ if (headless or headless2) and IS_WINDOWS:
1678
+ # https://stackoverflow.com/a/78999088/7058266
1679
+ chrome_options.add_argument("--window-position=-2400,-2400")
1680
+ else:
1681
+ if (
1682
+ hasattr(settings, "WINDOW_START_X")
1683
+ and isinstance(settings.WINDOW_START_X, int)
1684
+ and hasattr(settings, "WINDOW_START_Y")
1685
+ and isinstance(settings.WINDOW_START_Y, int)
1686
+ ):
1687
+ chrome_options.add_argument(
1688
+ "--window-position=%s,%s" % (
1689
+ settings.WINDOW_START_X, settings.WINDOW_START_Y
1690
+ )
1691
+ )
1692
+ # Handle Window Size
1672
1693
  if headless or headless2:
1673
- chrome_options.add_argument(
1674
- "--window-size=%s,%s" % (
1675
- settings.HEADLESS_START_WIDTH, settings.HEADLESS_START_HEIGHT
1694
+ if (
1695
+ hasattr(settings, "HEADLESS_START_WIDTH")
1696
+ and isinstance(settings.HEADLESS_START_WIDTH, int)
1697
+ and hasattr(settings, "HEADLESS_START_HEIGHT")
1698
+ and isinstance(settings.HEADLESS_START_HEIGHT, int)
1699
+ ):
1700
+ chrome_options.add_argument(
1701
+ "--window-size=%s,%s" % (
1702
+ settings.HEADLESS_START_WIDTH,
1703
+ settings.HEADLESS_START_HEIGHT,
1704
+ )
1676
1705
  )
1677
- )
1678
1706
  else:
1679
- chrome_options.add_argument(
1680
- "--window-size=%s,%s" % (
1681
- settings.CHROME_START_WIDTH, settings.CHROME_START_HEIGHT
1707
+ if (
1708
+ hasattr(settings, "CHROME_START_WIDTH")
1709
+ and isinstance(settings.CHROME_START_WIDTH, int)
1710
+ and hasattr(settings, "CHROME_START_HEIGHT")
1711
+ and isinstance(settings.CHROME_START_HEIGHT, int)
1712
+ ):
1713
+ chrome_options.add_argument(
1714
+ "--window-size=%s,%s" % (
1715
+ settings.CHROME_START_WIDTH,
1716
+ settings.CHROME_START_HEIGHT,
1717
+ )
1682
1718
  )
1683
- )
1684
1719
  if (
1685
1720
  not proxy_auth
1686
1721
  and not disable_csp
@@ -1739,7 +1774,10 @@ def _set_chrome_options(
1739
1774
  pass # Processed After Version Check
1740
1775
  elif headless:
1741
1776
  if not undetectable:
1742
- chrome_options.add_argument("--headless")
1777
+ if headless1:
1778
+ chrome_options.add_argument("--headless=old")
1779
+ else:
1780
+ chrome_options.add_argument("--headless")
1743
1781
  if undetectable and servername and servername != "localhost":
1744
1782
  # The Grid Node will need Chrome 109 or newer
1745
1783
  chrome_options.add_argument("--headless=new")
@@ -1858,8 +1896,12 @@ def _set_chrome_options(
1858
1896
  binary_location = binary_loc
1859
1897
  extra_disabled_features = []
1860
1898
  if chromium_arg:
1861
- # Can be a comma-separated list of Chromium args
1862
- chromium_arg_list = chromium_arg.split(",")
1899
+ # Can be a comma-separated list of Chromium args or a list
1900
+ chromium_arg_list = None
1901
+ if isinstance(chromium_arg, (list, tuple)):
1902
+ chromium_arg_list = chromium_arg
1903
+ else:
1904
+ chromium_arg_list = chromium_arg.split(",")
1863
1905
  for chromium_arg_item in chromium_arg_list:
1864
1906
  chromium_arg_item = chromium_arg_item.strip()
1865
1907
  if not chromium_arg_item.startswith("--"):
@@ -1868,13 +1910,11 @@ def _set_chrome_options(
1868
1910
  else:
1869
1911
  chromium_arg_item = "--" + chromium_arg_item
1870
1912
  if "remote-debugging-port=" in chromium_arg_item:
1871
- try:
1913
+ with suppress(Exception):
1872
1914
  # Extra processing for UC Mode
1873
1915
  chrome_options._remote_debugging_port = int(
1874
1916
  chromium_arg_item.split("remote-debugging-port=")[1]
1875
1917
  )
1876
- except Exception:
1877
- pass
1878
1918
  if "set-binary" in chromium_arg_item and not binary_location:
1879
1919
  br_app = "google-chrome"
1880
1920
  binary_loc = detect_b_ver.get_binary_location(
@@ -2159,6 +2199,7 @@ def get_driver(
2159
2199
  log_cdp_events=False,
2160
2200
  no_sandbox=False,
2161
2201
  disable_gpu=False,
2202
+ headless1=False,
2162
2203
  headless2=False,
2163
2204
  incognito=False,
2164
2205
  guest_mode=False,
@@ -2372,6 +2413,7 @@ def get_driver(
2372
2413
  log_cdp_events,
2373
2414
  no_sandbox,
2374
2415
  disable_gpu,
2416
+ headless1,
2375
2417
  headless2,
2376
2418
  incognito,
2377
2419
  guest_mode,
@@ -2428,6 +2470,7 @@ def get_driver(
2428
2470
  log_cdp_events,
2429
2471
  no_sandbox,
2430
2472
  disable_gpu,
2473
+ headless1,
2431
2474
  headless2,
2432
2475
  incognito,
2433
2476
  guest_mode,
@@ -2488,6 +2531,7 @@ def get_remote_driver(
2488
2531
  log_cdp_events,
2489
2532
  no_sandbox,
2490
2533
  disable_gpu,
2534
+ headless1,
2491
2535
  headless2,
2492
2536
  incognito,
2493
2537
  guest_mode,
@@ -2526,14 +2570,12 @@ def get_remote_driver(
2526
2570
  try:
2527
2571
  from seleniumwire import webdriver
2528
2572
  import blinker
2529
- try:
2573
+ with suppress(Exception):
2530
2574
  use_blinker_ver = constants.SeleniumWire.BLINKER_VER
2531
2575
  if blinker.__version__ != use_blinker_ver:
2532
2576
  shared_utils.pip_install(
2533
2577
  "blinker", version=use_blinker_ver
2534
2578
  )
2535
- except Exception:
2536
- pass
2537
2579
  del blinker
2538
2580
  except Exception:
2539
2581
  shared_utils.pip_install(
@@ -2625,6 +2667,7 @@ def get_remote_driver(
2625
2667
  log_cdp_events,
2626
2668
  no_sandbox,
2627
2669
  disable_gpu,
2670
+ headless1,
2628
2671
  headless2,
2629
2672
  incognito,
2630
2673
  guest_mode,
@@ -2797,6 +2840,7 @@ def get_remote_driver(
2797
2840
  log_cdp_events,
2798
2841
  no_sandbox,
2799
2842
  disable_gpu,
2843
+ headless1,
2800
2844
  headless2,
2801
2845
  incognito,
2802
2846
  guest_mode,
@@ -2916,6 +2960,7 @@ def get_local_driver(
2916
2960
  log_cdp_events,
2917
2961
  no_sandbox,
2918
2962
  disable_gpu,
2963
+ headless1,
2919
2964
  headless2,
2920
2965
  incognito,
2921
2966
  guest_mode,
@@ -2957,14 +3002,12 @@ def get_local_driver(
2957
3002
  try:
2958
3003
  from seleniumwire import webdriver
2959
3004
  import blinker
2960
- try:
3005
+ with suppress(Exception):
2961
3006
  use_blinker_ver = constants.SeleniumWire.BLINKER_VER
2962
3007
  if blinker.__version__ != use_blinker_ver:
2963
3008
  shared_utils.pip_install(
2964
3009
  "blinker", version=use_blinker_ver
2965
3010
  )
2966
- except Exception:
2967
- pass
2968
3011
  del blinker
2969
3012
  except Exception:
2970
3013
  shared_utils.pip_install(
@@ -3255,7 +3298,7 @@ def get_local_driver(
3255
3298
  edge_driver_version = None
3256
3299
  edgedriver_upgrade_needed = False
3257
3300
  if os.path.exists(LOCAL_EDGEDRIVER):
3258
- try:
3301
+ with suppress(Exception):
3259
3302
  output = subprocess.check_output(
3260
3303
  '"%s" --version' % LOCAL_EDGEDRIVER, shell=True
3261
3304
  )
@@ -3281,8 +3324,6 @@ def get_local_driver(
3281
3324
  edge_driver_version = output
3282
3325
  if driver_version == "keep":
3283
3326
  driver_version = edge_driver_version
3284
- except Exception:
3285
- pass
3286
3327
  use_version = find_edgedriver_version_to_use(
3287
3328
  use_version, driver_version
3288
3329
  )
@@ -3386,7 +3427,7 @@ def get_local_driver(
3386
3427
  edge_options.add_argument("--headless=new")
3387
3428
  elif headless and undetectable:
3388
3429
  # (For later: UC Mode doesn't support Edge now)
3389
- try:
3430
+ with suppress(Exception):
3390
3431
  if int(use_version) >= 109:
3391
3432
  edge_options.add_argument("--headless=new")
3392
3433
  elif (
@@ -3396,11 +3437,15 @@ def get_local_driver(
3396
3437
  edge_options.add_argument("--headless=chrome")
3397
3438
  else:
3398
3439
  pass # Will need Xvfb on Linux
3399
- except Exception:
3400
- pass
3401
3440
  elif headless:
3402
- if "--headless" not in edge_options.arguments:
3403
- edge_options.add_argument("--headless")
3441
+ if (
3442
+ "--headless" not in edge_options.arguments
3443
+ and "--headless=old" not in edge_options.arguments
3444
+ ):
3445
+ if headless1:
3446
+ edge_options.add_argument("--headless=old")
3447
+ else:
3448
+ edge_options.add_argument("--headless")
3404
3449
  if mobile_emulator and not is_using_uc(undetectable, browser_name):
3405
3450
  emulator_settings = {}
3406
3451
  device_metrics = {}
@@ -3422,20 +3467,49 @@ def get_local_driver(
3422
3467
  edge_options.add_experimental_option(
3423
3468
  "mobileEmulation", emulator_settings
3424
3469
  )
3470
+ # Handle Window Position
3471
+ if (headless or headless2) and IS_WINDOWS:
3472
+ # https://stackoverflow.com/a/78999088/7058266
3473
+ edge_options.add_argument("--window-position=-2400,-2400")
3474
+ else:
3475
+ if (
3476
+ hasattr(settings, "WINDOW_START_X")
3477
+ and isinstance(settings.WINDOW_START_X, int)
3478
+ and hasattr(settings, "WINDOW_START_Y")
3479
+ and isinstance(settings.WINDOW_START_Y, int)
3480
+ ):
3481
+ edge_options.add_argument(
3482
+ "--window-position=%s,%s" % (
3483
+ settings.WINDOW_START_X, settings.WINDOW_START_Y
3484
+ )
3485
+ )
3486
+ # Handle Window Size
3425
3487
  if headless or headless2:
3426
- edge_options.add_argument(
3427
- "--window-size=%s,%s" % (
3428
- settings.HEADLESS_START_WIDTH,
3429
- settings.HEADLESS_START_HEIGHT,
3488
+ if (
3489
+ hasattr(settings, "HEADLESS_START_WIDTH")
3490
+ and isinstance(settings.HEADLESS_START_WIDTH, int)
3491
+ and hasattr(settings, "HEADLESS_START_HEIGHT")
3492
+ and isinstance(settings.HEADLESS_START_HEIGHT, int)
3493
+ ):
3494
+ edge_options.add_argument(
3495
+ "--window-size=%s,%s" % (
3496
+ settings.HEADLESS_START_WIDTH,
3497
+ settings.HEADLESS_START_HEIGHT,
3498
+ )
3430
3499
  )
3431
- )
3432
3500
  else:
3433
- edge_options.add_argument(
3434
- "--window-size=%s,%s" % (
3435
- settings.CHROME_START_WIDTH,
3436
- settings.CHROME_START_HEIGHT,
3501
+ if (
3502
+ hasattr(settings, "CHROME_START_WIDTH")
3503
+ and isinstance(settings.CHROME_START_WIDTH, int)
3504
+ and hasattr(settings, "CHROME_START_HEIGHT")
3505
+ and isinstance(settings.CHROME_START_HEIGHT, int)
3506
+ ):
3507
+ edge_options.add_argument(
3508
+ "--window-size=%s,%s" % (
3509
+ settings.CHROME_START_WIDTH,
3510
+ settings.CHROME_START_HEIGHT,
3511
+ )
3437
3512
  )
3438
- )
3439
3513
  if user_data_dir and not is_using_uc(undetectable, browser_name):
3440
3514
  abs_path = os.path.abspath(user_data_dir)
3441
3515
  edge_options.add_argument("--user-data-dir=%s" % abs_path)
@@ -3569,7 +3643,11 @@ def get_local_driver(
3569
3643
  set_binary = False
3570
3644
  if chromium_arg:
3571
3645
  # Can be a comma-separated list of Chromium args
3572
- chromium_arg_list = chromium_arg.split(",")
3646
+ chromium_arg_list = None
3647
+ if isinstance(chromium_arg, (list, tuple)):
3648
+ chromium_arg_list = chromium_arg
3649
+ else:
3650
+ chromium_arg_list = chromium_arg.split(",")
3573
3651
  for chromium_arg_item in chromium_arg_list:
3574
3652
  chromium_arg_item = chromium_arg_item.strip()
3575
3653
  if not chromium_arg_item.startswith("--"):
@@ -3664,19 +3742,15 @@ def get_local_driver(
3664
3742
  constants.MultiBrowser.DRIVER_FIXING_LOCK
3665
3743
  )
3666
3744
  with edgedriver_fixing_lock:
3667
- try:
3745
+ with suppress(Exception):
3668
3746
  if not _was_driver_repaired():
3669
3747
  _repair_edgedriver(edge_version)
3670
3748
  _mark_driver_repaired()
3671
- except Exception:
3672
- pass
3673
3749
  else:
3674
- try:
3750
+ with suppress(Exception):
3675
3751
  if not _was_driver_repaired():
3676
3752
  _repair_edgedriver(edge_version)
3677
3753
  _mark_driver_repaired()
3678
- except Exception:
3679
- pass
3680
3754
  driver = Edge(service=service, options=edge_options)
3681
3755
  return extend_driver(driver)
3682
3756
  elif browser_name == constants.Browser.SAFARI:
@@ -3733,6 +3807,7 @@ def get_local_driver(
3733
3807
  log_cdp_events,
3734
3808
  no_sandbox,
3735
3809
  disable_gpu,
3810
+ headless1,
3736
3811
  headless2,
3737
3812
  incognito,
3738
3813
  guest_mode,
@@ -3828,7 +3903,7 @@ def get_local_driver(
3828
3903
  ch_driver_version = None
3829
3904
  path_chromedriver = chromedriver_on_path()
3830
3905
  if os.path.exists(LOCAL_CHROMEDRIVER):
3831
- try:
3906
+ with suppress(Exception):
3832
3907
  output = subprocess.check_output(
3833
3908
  '"%s" --version' % LOCAL_CHROMEDRIVER, shell=True
3834
3909
  )
@@ -3842,8 +3917,6 @@ def get_local_driver(
3842
3917
  ch_driver_version = output
3843
3918
  if driver_version == "keep":
3844
3919
  driver_version = ch_driver_version
3845
- except Exception:
3846
- pass
3847
3920
  elif path_chromedriver:
3848
3921
  try:
3849
3922
  make_driver_executable_if_not(path_chromedriver)
@@ -3852,7 +3925,7 @@ def get_local_driver(
3852
3925
  "\nWarning: Could not make chromedriver"
3853
3926
  " executable: %s" % e
3854
3927
  )
3855
- try:
3928
+ with suppress(Exception):
3856
3929
  output = subprocess.check_output(
3857
3930
  '"%s" --version' % path_chromedriver, shell=True
3858
3931
  )
@@ -3866,8 +3939,6 @@ def get_local_driver(
3866
3939
  ch_driver_version = output
3867
3940
  if driver_version == "keep":
3868
3941
  use_version = ch_driver_version
3869
- except Exception:
3870
- pass
3871
3942
  disable_build_check = True
3872
3943
  uc_driver_version = None
3873
3944
  if is_using_uc(undetectable, browser_name):
@@ -3909,8 +3980,14 @@ def get_local_driver(
3909
3980
  except Exception:
3910
3981
  pass # Will need Xvfb on Linux
3911
3982
  elif headless:
3912
- if "--headless" not in chrome_options.arguments:
3913
- chrome_options.add_argument("--headless")
3983
+ if (
3984
+ "--headless" not in chrome_options.arguments
3985
+ and "--headless=old" not in chrome_options.arguments
3986
+ ):
3987
+ if headless1:
3988
+ chrome_options.add_argument("--headless=old")
3989
+ else:
3990
+ chrome_options.add_argument("--headless")
3914
3991
  if LOCAL_CHROMEDRIVER and os.path.exists(LOCAL_CHROMEDRIVER):
3915
3992
  try:
3916
3993
  make_driver_executable_if_not(LOCAL_CHROMEDRIVER)
@@ -4060,7 +4137,7 @@ def get_local_driver(
4060
4137
  if IS_ARM_MAC and use_uc:
4061
4138
  intel_for_uc = True # Use Intel driver for UC Mode
4062
4139
  if os.path.exists(LOCAL_CHROMEDRIVER):
4063
- try:
4140
+ with suppress(Exception):
4064
4141
  output = subprocess.check_output(
4065
4142
  '"%s" --version' % LOCAL_CHROMEDRIVER,
4066
4143
  shell=True,
@@ -4073,8 +4150,6 @@ def get_local_driver(
4073
4150
  output = full_ch_driver_version.split(".")[0]
4074
4151
  if int(output) >= 2:
4075
4152
  ch_driver_version = output
4076
- except Exception:
4077
- pass
4078
4153
  if (
4079
4154
  (
4080
4155
  not use_uc
@@ -4178,6 +4253,12 @@ def get_local_driver(
4178
4253
  chrome_options.arguments.remove(
4179
4254
  "--headless"
4180
4255
  )
4256
+ if "--headless=old" in (
4257
+ chrome_options.arguments
4258
+ ):
4259
+ chrome_options.arguments.remove(
4260
+ "--headless=old"
4261
+ )
4181
4262
  uc_chrome_version = None
4182
4263
  if (
4183
4264
  use_version.isnumeric()
@@ -4212,7 +4293,7 @@ def get_local_driver(
4212
4293
  chrome_options.add_argument(
4213
4294
  "--user-agent=%s" % user_agent
4214
4295
  )
4215
- try:
4296
+ with suppress(Exception):
4216
4297
  if (
4217
4298
  (
4218
4299
  not user_agent
@@ -4251,6 +4332,7 @@ def get_local_driver(
4251
4332
  False, # log_cdp_events
4252
4333
  no_sandbox,
4253
4334
  disable_gpu,
4335
+ False, # headless1
4254
4336
  False, # headless2
4255
4337
  incognito,
4256
4338
  guest_mode,
@@ -4318,7 +4400,7 @@ def get_local_driver(
4318
4400
  service=service,
4319
4401
  options=headless_options,
4320
4402
  )
4321
- try:
4403
+ with suppress(Exception):
4322
4404
  user_agent = driver.execute_script(
4323
4405
  "return navigator.userAgent;"
4324
4406
  )
@@ -4340,11 +4422,7 @@ def get_local_driver(
4340
4422
  "--user-agent=%s" % user_agent
4341
4423
  )
4342
4424
  sb_config.uc_agent_cache = user_agent
4343
- except Exception:
4344
- pass
4345
4425
  driver.quit()
4346
- except Exception:
4347
- pass
4348
4426
  uc_path = None
4349
4427
  if os.path.exists(LOCAL_UC_DRIVER):
4350
4428
  uc_path = LOCAL_UC_DRIVER
@@ -4496,6 +4574,7 @@ def get_local_driver(
4496
4574
  False, # log_cdp_events
4497
4575
  no_sandbox,
4498
4576
  disable_gpu,
4577
+ False, # headless1
4499
4578
  False, # headless2
4500
4579
  incognito,
4501
4580
  guest_mode,
@@ -4667,13 +4746,11 @@ def get_local_driver(
4667
4746
  "mobile": True
4668
4747
  }
4669
4748
  )
4670
- try:
4749
+ with suppress(Exception):
4671
4750
  driver.execute_cdp_cmd(
4672
4751
  'Emulation.setDeviceMetricsOverride',
4673
4752
  set_device_metrics_override
4674
4753
  )
4675
- except Exception:
4676
- pass
4677
4754
  return extend_driver(driver)
4678
4755
  else: # Running headless on Linux (and not using --uc)
4679
4756
  try:
@@ -4719,23 +4796,19 @@ def get_local_driver(
4719
4796
  )
4720
4797
  with chromedr_fixing_lock:
4721
4798
  if not _was_driver_repaired():
4722
- try:
4799
+ with suppress(Exception):
4723
4800
  _repair_chromedriver(
4724
4801
  chrome_options, chrome_options, mcv
4725
4802
  )
4726
4803
  _mark_driver_repaired()
4727
- except Exception:
4728
- pass
4729
4804
  else:
4730
4805
  if not _was_driver_repaired():
4731
- try:
4806
+ with suppress(Exception):
4732
4807
  _repair_chromedriver(
4733
4808
  chrome_options, chrome_options, mcv
4734
4809
  )
4735
- except Exception:
4736
- pass
4737
4810
  _mark_driver_repaired()
4738
- try:
4811
+ with suppress(Exception):
4739
4812
  service = ChromeService(
4740
4813
  log_output=os.devnull,
4741
4814
  service_args=["--disable-build-check"],
@@ -4745,8 +4818,6 @@ def get_local_driver(
4745
4818
  options=chrome_options,
4746
4819
  )
4747
4820
  return extend_driver(driver)
4748
- except Exception:
4749
- pass
4750
4821
  # Use the virtual display on Linux during headless errors
4751
4822
  logging.debug(
4752
4823
  "\nWarning: Chrome failed to launch in"
@@ -4755,6 +4826,8 @@ def get_local_driver(
4755
4826
  )
4756
4827
  if "--headless" in chrome_options.arguments:
4757
4828
  chrome_options.arguments.remove("--headless")
4829
+ if "--headless=old" in chrome_options.arguments:
4830
+ chrome_options.arguments.remove("--headless=old")
4758
4831
  service = ChromeService(
4759
4832
  log_output=os.devnull,
4760
4833
  service_args=["--disable-build-check"]
@@ -4767,14 +4840,12 @@ def get_local_driver(
4767
4840
  if is_using_uc(undetectable, browser_name):
4768
4841
  raise
4769
4842
  # Try again if Chrome didn't launch
4770
- try:
4843
+ with suppress(Exception):
4771
4844
  service = ChromeService(service_args=["--disable-build-check"])
4772
4845
  driver = webdriver.Chrome(
4773
4846
  service=service, options=chrome_options
4774
4847
  )
4775
4848
  return extend_driver(driver)
4776
- except Exception:
4777
- pass
4778
4849
  if user_data_dir:
4779
4850
  print("\nUnable to set user_data_dir while starting Chrome!\n")
4780
4851
  raise