|
| 1 | +import atexit |
| 2 | +import os |
| 3 | +import tempfile |
| 4 | + |
| 5 | +from msedge.selenium_tools import Edge, EdgeOptions # noqa: F401, F403 |
| 6 | + |
| 7 | +from ..util import cleanup_temp_dir |
| 8 | + |
| 9 | + |
| 10 | +def default_options(headless=False, download_folder_path=None, user_data_dir=None): |
| 11 | + edge_options = EdgeOptions() |
| 12 | + edge_options.use_chrome = True |
| 13 | + edge_options.add_argument("--disable-extensions") |
| 14 | + edge_options.add_argument("--remote-debugging-port=0") |
| 15 | + edge_options.add_argument("--no-first-run") |
| 16 | + edge_options.add_argument("--no-default-browser-check") |
| 17 | + edge_options.add_argument("--disable-background-networking") |
| 18 | + edge_options.add_argument("--disable-background-timer-throttling") |
| 19 | + edge_options.add_argument("--disable-client-side-phishing-detection") |
| 20 | + edge_options.add_argument("--disable-default-apps") |
| 21 | + edge_options.add_argument("--disable-extensions") |
| 22 | + edge_options.add_argument("--disable-hang-monitor") |
| 23 | + edge_options.add_argument("--disable-popup-blocking") |
| 24 | + edge_options.add_argument("--disable-prompt-on-repost") |
| 25 | + edge_options.add_argument("--disable-syncdisable-translate") |
| 26 | + edge_options.add_argument("--metrics-recording-only") |
| 27 | + edge_options.add_argument("--safebrowsing-disable-auto-update") |
| 28 | + |
| 29 | + edge_options.add_argument("--disable-blink-features=AutomationControlled") |
| 30 | + |
| 31 | + # Disable banner for Browser being remote-controlled |
| 32 | + edge_options.add_experimental_option("excludeSwitches", ["enable-automation"]) |
| 33 | + edge_options.add_experimental_option('useAutomationExtension', False) |
| 34 | + |
| 35 | + if headless: |
| 36 | + edge_options.add_argument("--headless") |
| 37 | + edge_options.add_argument("--disable-gpu") |
| 38 | + edge_options.add_argument("--hide-scrollbars") |
| 39 | + edge_options.add_argument("--mute-audio") |
| 40 | + |
| 41 | + if not user_data_dir: |
| 42 | + temp_dir = tempfile.TemporaryDirectory(prefix="botcity_") |
| 43 | + user_data_dir = temp_dir.name |
| 44 | + atexit.register(cleanup_temp_dir, temp_dir) |
| 45 | + |
| 46 | + edge_options.add_argument(f"--user-data-dir={user_data_dir}") |
| 47 | + |
| 48 | + if not download_folder_path: |
| 49 | + download_folder_path = os.path.join(os.path.expanduser("~"), "Desktop") |
| 50 | + |
| 51 | + # Set the Downloads default folder |
| 52 | + prefs = {"download.default_directory": download_folder_path} |
| 53 | + edge_options.add_experimental_option("prefs", prefs) |
| 54 | + |
| 55 | + return edge_options |
0 commit comments