Merge 4c486320946185cccaa1f7eedca6b5cb69585cab into ce5369dd413cd71a81ce38a5ccd379f6c9352e23

This commit is contained in:
ilike2burnthing 2025-03-04 03:06:18 +01:00 committed by GitHub
commit c62760d601
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 16 deletions

View File

@ -290,20 +290,10 @@ def click_verify(driver: WebDriver):
time.sleep(2)
def get_correct_window(driver: WebDriver) -> WebDriver:
if len(driver.window_handles) > 1:
for window_handle in driver.window_handles:
driver.switch_to.window(window_handle)
current_url = driver.current_url
if not current_url.startswith("devtools://devtools"):
return driver
return driver
def access_page(driver: WebDriver, url: str) -> None:
driver.get(url)
driver.start_session()
driver.start_session() # required to bypass Cloudflare
def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> ChallengeResolutionT:
@ -318,7 +308,6 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge
_post_request(req, driver)
else:
access_page(driver, req.url)
driver = get_correct_window(driver)
# set cookies if required
if req.cookies is not None and len(req.cookies) > 0:
@ -331,7 +320,6 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge
_post_request(req, driver)
else:
access_page(driver, req.url)
driver = get_correct_window(driver)
# wait for the page
if utils.get_config_log_html():
@ -390,6 +378,10 @@ def _evil_logic(req: V1RequestBase, driver: WebDriver, method: str) -> Challenge
logging.debug("Timeout waiting for selector")
click_verify(driver)
driver.execute_script(f'window.open("{req.url}", "_blank");')
time.sleep(3)
driver.close()
driver.switch_to.window(window_name=driver.window_handles[0])
# update the html (cloudflare reloads the page every 5 s)
html_element = driver.find_element(By.TAG_NAME, "html")
@ -452,4 +444,3 @@ def _post_request(req: V1RequestBase, driver: WebDriver):
</html>"""
driver.get("data:text/html;charset=utf-8,{html_content}".format(html_content=html_content))
driver.start_session()
driver.start_session() # required to bypass Cloudflare

View File

@ -148,6 +148,9 @@ def get_webdriver(proxy: dict = None) -> WebDriver:
# https://github.com/microsoft/vscode/issues/127800#issuecomment-873342069
# https://peter.sh/experiments/chromium-command-line-switches/#use-gl
options.add_argument('--use-gl=swiftshader')
# required to bypass Cloudflare
# https://github.com/FlareSolverr/FlareSolverr/issues/1036
options.add_argument("--disable-popup-blocking")
language = os.environ.get('LANG', None)
if language is not None:
@ -177,8 +180,6 @@ def get_webdriver(proxy: dict = None) -> WebDriver:
# For normal headless mode:
# options.add_argument('--headless')
options.add_argument("--auto-open-devtools-for-tabs")
# if we are inside the Docker container, we avoid downloading the driver
driver_exe_path = None
version_main = None