Compare commits

...

8 Commits

Author SHA1 Message Date
MCG-pok
f75994197c Update css selector to get shadowed iframe 2024-08-14 14:05:04 +03:00
MCG-pok
42714b248f add js click on iframe_body 2024-08-14 14:05:04 +03:00
MCG-pok
2900c58165 Access iframe in closed shadow root + click on checkbox from iframe body 2024-08-14 14:05:04 +03:00
ilike2burnthing
a798561338 Bump requests version
*.0 was yanked
2024-07-30 02:38:13 +01:00
Bogdan
eb680efc90 Don't build docker images for PRs from forks (#1281) 2024-07-20 22:08:40 +03:00
ilike2burnthing
0f8f0bec25 revert and bump action version 2024-07-20 19:41:49 +01:00
ilike2burnthing
3d9bc5627b Change to GITHUB_TOKEN for GHRC login 2024-07-20 14:21:34 +01:00
ilike2burnthing
dd7eaee2e3 Bump requirements
resolves Dependabot alerts
2024-07-12 17:11:40 +01:00
3 changed files with 40 additions and 14 deletions

View File

@@ -14,6 +14,7 @@ concurrency:
jobs:
build-docker-images:
if: ${{ !github.event.pull_request.head.repo.fork }}
runs-on: ubuntu-22.04
steps:
- name: Checkout
@@ -56,7 +57,7 @@ jobs:
password: ${{ secrets.GH_PAT }}
- name: Build and push
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: ./Dockerfile

View File

@@ -4,8 +4,8 @@ selenium==4.15.2
func-timeout==4.3.5
prometheus-client==0.17.1
# required by undetected_chromedriver
requests==2.31.0
certifi==2023.7.22
requests==2.32.3
certifi==2024.07.04
websockets==11.0.3
# only required for linux and macos
xvfbwrapper==0.2.9; platform_system != "Windows"

View File

@@ -219,6 +219,20 @@ def _cmd_sessions_destroy(req: V1RequestBase) -> V1ResponseBase:
"message": "The session has been removed."
})
def _init_driver(driver):
try:
driver.execute_cdp_cmd('Page.enable', {})
driver.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
'source': """
Element.prototype._as = Element.prototype.attachShadow;
Element.prototype.attachShadow = function (params) {
return this._as({mode: "open"})
};
"""
})
except Exception as e:
logging.debug("Driver init exception: %s", repr(e))
def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
timeout = int(req.maxTimeout) / 1000
@@ -239,6 +253,7 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
else:
driver = utils.get_webdriver(req.proxy)
logging.debug('New instance of webdriver has been created to perform the request')
_init_driver(driver)
return func_timeout(timeout, _evil_logic, (req, driver, method))
except FunctionTimedOut:
raise Exception(f'Error solving the challenge. Timeout after {timeout} seconds.')
@@ -252,23 +267,33 @@ def _resolve_challenge(req: V1RequestBase, method: str) -> ChallengeResolutionT:
logging.debug('A used instance of webdriver has been destroyed')
def get_shadowed_iframe(driver: WebDriver, css_selector: str):
logging.debug("Getting ShadowRoot by selector: %s", css_selector)
shadow_element = driver.execute_script("""
return document.querySelector(arguments[0]).shadowRoot.firstChild;
""", css_selector)
if shadow_element:
logging.debug("iframe found")
else:
logging.debug("iframe not found")
return shadow_element
def click_verify(driver: WebDriver):
try:
logging.debug("Try to find the Cloudflare verify checkbox...")
iframe = driver.find_element(By.XPATH, "//iframe[starts-with(@id, 'cf-chl-widget-')]")
iframe = get_shadowed_iframe(driver, "div:not(:has(div))")
driver.switch_to.frame(iframe)
checkbox = driver.find_element(
by=By.XPATH,
value='//*[@id="content"]/div/div/label/input',
)
if checkbox:
iframe_body = driver.find_element(By.CSS_SELECTOR, "body")
if iframe_body:
iframe_body.click()
actions = ActionChains(driver)
actions.move_to_element_with_offset(checkbox, 5, 7)
actions.click(checkbox)
actions.move_to_element_with_offset(iframe_body, 10, 10)
actions.click(iframe_body)
actions.perform()
logging.debug("Cloudflare verify checkbox found and clicked!")
except Exception:
logging.debug("Cloudflare verify checkbox not found on the page.")
logging.debug("Attempted to click on iframe body")
except Exception as e:
logging.debug("Cloudflare verify checkbox not found on the page. %s", repr(e))
finally:
driver.switch_to.default_content()