88from selenium .webdriver import Edge , EdgeOptions # noqa: F401, F403
99from selenium .webdriver .edge .service import Service as EdgeService # noqa: F401, F403
1010
11+ from ..util import is_admin
12+
1113
1214def default_options (headless = False , download_folder_path = None , user_data_dir = None ,
1315 page_load_strategy = "normal" , binary_path : str = None ) -> EdgeOptions :
@@ -48,10 +50,16 @@ def default_options(headless=False, download_folder_path=None, user_data_dir=Non
4850 edge_options .add_argument ("--disable-features=msSmartScreenProtection" )
4951 edge_options .add_argument ("--disable-blink-features=AutomationControlled" )
5052
51- # Disable banner for Browser being remote-controlled
52- edge_options .add_experimental_option ("excludeSwitches" , ["enable-automation" ])
5353 edge_options .add_experimental_option ('useAutomationExtension' , False )
5454
55+ # Check if user is root
56+ if is_admin ():
57+ if os .name == "posix" :
58+ edge_options .add_argument ("--no-sandbox" )
59+ else :
60+ # Disable banner for Browser being remote-controlled
61+ edge_options .add_experimental_option ("excludeSwitches" , ["enable-automation" ])
62+
5563 if headless :
5664 edge_options .add_argument ("--headless" )
5765 edge_options .add_argument ("--headless=new" )
@@ -60,14 +68,6 @@ def default_options(headless=False, download_folder_path=None, user_data_dir=Non
6068 edge_options .add_argument ("--hide-scrollbars" )
6169 edge_options .add_argument ("--mute-audio" )
6270
63- # Check if user is root
64- try :
65- # This is only valid with Unix
66- if os .geteuid () == 0 :
67- edge_options .add_argument ("--no-sandbox" )
68- except AttributeError :
69- pass
70-
7171 edge_options ._botcity_temp_dir = None
7272 if not user_data_dir :
7373 temp_dir = tempfile .TemporaryDirectory (prefix = "botcity_" )
0 commit comments