@@ -602,16 +602,32 @@ def install_pyautogui_if_missing(driver):
602602 and not (sb_config .headless or sb_config .headless2 )
603603 ):
604604 from sbvirtualdisplay import Display
605- try :
605+ xvfb_width = 1366
606+ xvfb_height = 768
607+ if (
608+ hasattr (sb_config , "_xvfb_width" )
609+ and sb_config ._xvfb_width
610+ and isinstance (sb_config ._xvfb_width , int )
611+ and hasattr (sb_config , "_xvfb_height" )
612+ and sb_config ._xvfb_height
613+ and isinstance (sb_config ._xvfb_height , int )
614+ ):
615+ xvfb_width = sb_config ._xvfb_width
616+ xvfb_height = sb_config ._xvfb_height
617+ if xvfb_width < 1024 :
618+ xvfb_width = 1024
619+ sb_config ._xvfb_width = xvfb_width
620+ if xvfb_height < 768 :
621+ xvfb_height = 768
622+ sb_config ._xvfb_height = xvfb_height
623+ with suppress (Exception ):
606624 xvfb_display = Display (
607625 visible = True ,
608- size = (1366 , 768 ),
626+ size = (xvfb_width , xvfb_height ),
609627 backend = "xvfb" ,
610628 use_xauth = True ,
611629 )
612630 xvfb_display .start ()
613- except Exception :
614- pass
615631
616632
617633def get_configured_pyautogui (pyautogui_copy ):
@@ -1669,18 +1685,49 @@ def _set_chrome_options(
16691685 chrome_options .add_experimental_option (
16701686 "mobileEmulation" , emulator_settings
16711687 )
1688+ # Handle Window Position
1689+ if (headless or headless2 ) and IS_WINDOWS :
1690+ # https://stackoverflow.com/a/78999088/7058266
1691+ chrome_options .add_argument ("--window-position=-2400,-2400" )
1692+ else :
1693+ if (
1694+ hasattr (settings , "WINDOW_START_X" )
1695+ and isinstance (settings .WINDOW_START_X , int )
1696+ and hasattr (settings , "WINDOW_START_Y" )
1697+ and isinstance (settings .WINDOW_START_Y , int )
1698+ ):
1699+ chrome_options .add_argument (
1700+ "--window-position=%s,%s" % (
1701+ settings .WINDOW_START_X , settings .WINDOW_START_Y
1702+ )
1703+ )
1704+ # Handle Window Size
16721705 if headless or headless2 :
1673- chrome_options .add_argument (
1674- "--window-size=%s,%s" % (
1675- settings .HEADLESS_START_WIDTH , settings .HEADLESS_START_HEIGHT
1706+ if (
1707+ hasattr (settings , "HEADLESS_START_WIDTH" )
1708+ and isinstance (settings .HEADLESS_START_WIDTH , int )
1709+ and hasattr (settings , "HEADLESS_START_HEIGHT" )
1710+ and isinstance (settings .HEADLESS_START_HEIGHT , int )
1711+ ):
1712+ chrome_options .add_argument (
1713+ "--window-size=%s,%s" % (
1714+ settings .HEADLESS_START_WIDTH ,
1715+ settings .HEADLESS_START_HEIGHT ,
1716+ )
16761717 )
1677- )
16781718 else :
1679- chrome_options .add_argument (
1680- "--window-size=%s,%s" % (
1681- settings .CHROME_START_WIDTH , settings .CHROME_START_HEIGHT
1719+ if (
1720+ hasattr (settings , "CHROME_START_WIDTH" )
1721+ and isinstance (settings .CHROME_START_WIDTH , int )
1722+ and hasattr (settings , "CHROME_START_HEIGHT" )
1723+ and isinstance (settings .CHROME_START_HEIGHT , int )
1724+ ):
1725+ chrome_options .add_argument (
1726+ "--window-size=%s,%s" % (
1727+ settings .CHROME_START_WIDTH ,
1728+ settings .CHROME_START_HEIGHT ,
1729+ )
16821730 )
1683- )
16841731 if (
16851732 not proxy_auth
16861733 and not disable_csp
@@ -1858,8 +1905,12 @@ def _set_chrome_options(
18581905 binary_location = binary_loc
18591906 extra_disabled_features = []
18601907 if chromium_arg :
1861- # Can be a comma-separated list of Chromium args
1862- chromium_arg_list = chromium_arg .split ("," )
1908+ # Can be a comma-separated list of Chromium args or a list
1909+ chromium_arg_list = None
1910+ if isinstance (chromium_arg , (list , tuple )):
1911+ chromium_arg_list = chromium_arg
1912+ else :
1913+ chromium_arg_list = chromium_arg .split ("," )
18631914 for chromium_arg_item in chromium_arg_list :
18641915 chromium_arg_item = chromium_arg_item .strip ()
18651916 if not chromium_arg_item .startswith ("--" ):
@@ -3422,20 +3473,49 @@ def get_local_driver(
34223473 edge_options .add_experimental_option (
34233474 "mobileEmulation" , emulator_settings
34243475 )
3476+ # Handle Window Position
3477+ if (headless or headless2 ) and IS_WINDOWS :
3478+ # https://stackoverflow.com/a/78999088/7058266
3479+ edge_options .add_argument ("--window-position=-2400,-2400" )
3480+ else :
3481+ if (
3482+ hasattr (settings , "WINDOW_START_X" )
3483+ and isinstance (settings .WINDOW_START_X , int )
3484+ and hasattr (settings , "WINDOW_START_Y" )
3485+ and isinstance (settings .WINDOW_START_Y , int )
3486+ ):
3487+ edge_options .add_argument (
3488+ "--window-position=%s,%s" % (
3489+ settings .WINDOW_START_X , settings .WINDOW_START_Y
3490+ )
3491+ )
3492+ # Handle Window Size
34253493 if headless or headless2 :
3426- edge_options .add_argument (
3427- "--window-size=%s,%s" % (
3428- settings .HEADLESS_START_WIDTH ,
3429- settings .HEADLESS_START_HEIGHT ,
3494+ if (
3495+ hasattr (settings , "HEADLESS_START_WIDTH" )
3496+ and isinstance (settings .HEADLESS_START_WIDTH , int )
3497+ and hasattr (settings , "HEADLESS_START_HEIGHT" )
3498+ and isinstance (settings .HEADLESS_START_HEIGHT , int )
3499+ ):
3500+ edge_options .add_argument (
3501+ "--window-size=%s,%s" % (
3502+ settings .HEADLESS_START_WIDTH ,
3503+ settings .HEADLESS_START_HEIGHT ,
3504+ )
34303505 )
3431- )
34323506 else :
3433- edge_options .add_argument (
3434- "--window-size=%s,%s" % (
3435- settings .CHROME_START_WIDTH ,
3436- settings .CHROME_START_HEIGHT ,
3507+ if (
3508+ hasattr (settings , "CHROME_START_WIDTH" )
3509+ and isinstance (settings .CHROME_START_WIDTH , int )
3510+ and hasattr (settings , "CHROME_START_HEIGHT" )
3511+ and isinstance (settings .CHROME_START_HEIGHT , int )
3512+ ):
3513+ edge_options .add_argument (
3514+ "--window-size=%s,%s" % (
3515+ settings .CHROME_START_WIDTH ,
3516+ settings .CHROME_START_HEIGHT ,
3517+ )
34373518 )
3438- )
34393519 if user_data_dir and not is_using_uc (undetectable , browser_name ):
34403520 abs_path = os .path .abspath (user_data_dir )
34413521 edge_options .add_argument ("--user-data-dir=%s" % abs_path )
@@ -3569,7 +3649,11 @@ def get_local_driver(
35693649 set_binary = False
35703650 if chromium_arg :
35713651 # Can be a comma-separated list of Chromium args
3572- chromium_arg_list = chromium_arg .split ("," )
3652+ chromium_arg_list = None
3653+ if isinstance (chromium_arg , (list , tuple )):
3654+ chromium_arg_list = chromium_arg
3655+ else :
3656+ chromium_arg_list = chromium_arg .split ("," )
35733657 for chromium_arg_item in chromium_arg_list :
35743658 chromium_arg_item = chromium_arg_item .strip ()
35753659 if not chromium_arg_item .startswith ("--" ):
0 commit comments