|
7 | 7 | from msedge.selenium_tools import Edge, EdgeOptions # noqa: F401, F403 |
8 | 8 | from selenium.webdriver.common.desired_capabilities import DesiredCapabilities |
9 | 9 |
|
| 10 | +from ..util import is_admin |
| 11 | + |
10 | 12 |
|
11 | 13 | def default_options(headless=False, download_folder_path=None, user_data_dir=None, |
12 | 14 | page_load_strategy="normal") -> EdgeOptions: |
@@ -44,25 +46,23 @@ def default_options(headless=False, download_folder_path=None, user_data_dir=Non |
44 | 46 |
|
45 | 47 | edge_options.add_argument("--disable-blink-features=AutomationControlled") |
46 | 48 |
|
47 | | - # Disable banner for Browser being remote-controlled |
48 | | - edge_options.add_experimental_option("excludeSwitches", ["enable-automation"]) |
49 | 49 | edge_options.add_experimental_option('useAutomationExtension', False) |
50 | 50 |
|
| 51 | + # Check if user is root |
| 52 | + if is_admin(): |
| 53 | + if os.name == "posix": |
| 54 | + edge_options.add_argument("--no-sandbox") |
| 55 | + else: |
| 56 | + # Disable banner for Browser being remote-controlled |
| 57 | + edge_options.add_experimental_option("excludeSwitches", ["enable-automation"]) |
| 58 | + |
51 | 59 | if headless: |
52 | 60 | edge_options.add_argument("--headless") |
53 | 61 | edge_options.add_argument("--headless=new") |
54 | 62 | edge_options.add_argument("--disable-gpu") |
55 | 63 | edge_options.add_argument("--hide-scrollbars") |
56 | 64 | edge_options.add_argument("--mute-audio") |
57 | 65 |
|
58 | | - # Check if user is root |
59 | | - try: |
60 | | - # This is only valid with Unix |
61 | | - if os.geteuid() == 0: |
62 | | - edge_options.add_argument("--no-sandbox") |
63 | | - except AttributeError: |
64 | | - pass |
65 | | - |
66 | 66 | edge_options._botcity_temp_dir = None |
67 | 67 | if not user_data_dir: |
68 | 68 | temp_dir = tempfile.TemporaryDirectory(prefix="botcity_") |
|
0 commit comments