MCPcopy
hub / github.com/FlareSolverr/FlareSolverr / get_webdriver

Function get_webdriver

src/utils.py:132–225  ·  view source on GitHub ↗
(proxy: dict = None)

Source from the content-addressed store, hash-verified

130
131
132def 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()

Callers 1

get_user_agentFunction · 0.85

Calls 7

create_proxy_extensionFunction · 0.85
get_config_headlessFunction · 0.85
start_xvfb_displayFunction · 0.85
get_chrome_major_versionFunction · 0.85
get_chrome_exe_pathFunction · 0.85
existsMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected