(proxy: dict = None)
| 130 | |
| 131 | |
| 132 | def get_webdriver(proxy: dict = None) -> WebDriver: |
| 133 | global PATCHED_DRIVER_PATH, USER_AGENT |
| 134 | logging.debug('Launching web browser...') |
| 135 | |
| 136 | # undetected_chromedriver |
| 137 | options = uc.ChromeOptions() |
| 138 | options.add_argument('--no-sandbox') |
| 139 | options.add_argument('--window-size=1920,1080') |
| 140 | options.add_argument('--disable-search-engine-choice-screen') |
| 141 | # todo: this param shows a warning in chrome head-full |
| 142 | options.add_argument('--disable-setuid-sandbox') |
| 143 | options.add_argument('--disable-dev-shm-usage') |
| 144 | # this option removes the zygote sandbox (it seems that the resolution is a bit faster) |
| 145 | options.add_argument('--no-zygote') |
| 146 | # attempt to fix Docker ARM32 build |
| 147 | IS_ARMARCH = platform.machine().startswith(('arm', 'aarch')) |
| 148 | if IS_ARMARCH: |
| 149 | options.add_argument('--disable-gpu-sandbox') |
| 150 | options.add_argument('--ignore-certificate-errors') |
| 151 | options.add_argument('--ignore-ssl-errors') |
| 152 | |
| 153 | language = os.environ.get('LANG', None) |
| 154 | if language is not None: |
| 155 | options.add_argument('--accept-lang=%s' % language) |
| 156 | |
| 157 | # Fix for Chrome 117 | https://github.com/FlareSolverr/FlareSolverr/issues/910 |
| 158 | if USER_AGENT is not None: |
| 159 | options.add_argument('--user-agent=%s' % USER_AGENT) |
| 160 | |
| 161 | proxy_extension_dir = None |
| 162 | if proxy and all(key in proxy for key in ['url', 'username', 'password']): |
| 163 | proxy_extension_dir = create_proxy_extension(proxy) |
| 164 | options.add_argument("--disable-features=DisableLoadExtensionCommandLineSwitch") |
| 165 | options.add_argument("--load-extension=%s" % os.path.abspath(proxy_extension_dir)) |
| 166 | elif proxy and 'url' in proxy: |
| 167 | proxy_url = proxy['url'] |
| 168 | logging.debug("Using webdriver proxy: %s", proxy_url) |
| 169 | options.add_argument('--proxy-server=%s' % proxy_url) |
| 170 | |
| 171 | # note: headless mode is detected (headless = True) |
| 172 | # we launch the browser in head-full mode with the window hidden |
| 173 | windows_headless = False |
| 174 | if get_config_headless(): |
| 175 | if os.name == 'nt': |
| 176 | windows_headless = True |
| 177 | else: |
| 178 | start_xvfb_display() |
| 179 | # For normal headless mode: |
| 180 | # options.add_argument('--headless') |
| 181 | |
| 182 | # if we are inside the Docker container, we avoid downloading the driver |
| 183 | driver_exe_path = None |
| 184 | version_main = None |
| 185 | if os.path.exists("/app/chromedriver"): |
| 186 | # running inside Docker |
| 187 | driver_exe_path = "/app/chromedriver" |
| 188 | else: |
| 189 | version_main = get_chrome_major_version() |
no test coverage detected