Skip to content

Commit 5baa8bd

Browse files
authored
fix: update handleCloudflareChallenge for new Cloudflare challenge markup (#3717)
## What `handleCloudflareChallenge` stopped detecting the Cloudflare challenge. Cloudflare inserted a `.footer-wrapper` element between `.footer-inner` and `.diagnostic-wrapper` on the challenge page, which broke the direct-child detection selector — so the helper returned immediately and the request handler ran against an unsolved "Just a moment..." page (exactly the report in #3629). - Detection now matches by **descendants** (`.footer .footer-inner .diagnostic-wrapper .ray-id`) so intervening wrappers don't break it. - The click position now targets the **actual challenge widget** (the box holding the Turnstile checkbox input), falling back to the old `.main-content div` for older layouts. ## e2e alignment The `camoufox-cloudflare` e2e was also a false green: its own `isBlocked` check used the same broken selector, so the assertion always passed. Fixed that selector, and aligned the browser stack — `camoufox-js@^0.11.0` installs the Camoufox **150** (Firefox 150) build, so the actor now uses **Playwright 1.60** (also Firefox 150). A mismatched Firefox crashes playwright-core on Cloudflare's uncaught page errors (`pageError.location` is undefined), so the versions must line up. Depends on camoufox-js ≥ 0.11.0 (apify/camoufox-js#283). Closes #3629
1 parent 31512a3 commit 5baa8bd

5 files changed

Lines changed: 22 additions & 16 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
"apify-node-curl-impersonate": "^1.0.15",
8888
"basic-auth-parser": "^0.0.2",
8989
"body-parser": "^2.0.0",
90-
"camoufox-js": "^0.10.0",
90+
"camoufox-js": "^0.11.0",
9191
"commitlint": "^21.0.0",
9292
"cross-env": "^10.0.0",
9393
"deep-equal": "^2.0.5",

packages/playwright-crawler/src/internals/utils/playwright-utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,9 @@ async function handleCloudflareChallenge(
753753

754754
options.isChallengeCallback ??= async () => {
755755
return await page.evaluate(async () => {
756-
return !!document.querySelector('.footer > .footer-inner > .diagnostic-wrapper > .ray-id');
756+
// Cloudflare nests the ray ID under varying wrapper elements, so we match by descendants
757+
// instead of a direct-child chain (e.g. a `.footer-wrapper` was inserted in between).
758+
return !!document.querySelector('.footer .footer-inner .diagnostic-wrapper .ray-id');
757759
});
758760
};
759761

@@ -782,7 +784,11 @@ async function handleCloudflareChallenge(
782784

783785
const bb = await page
784786
.evaluate(() => {
785-
const div = document.querySelector('.main-content div');
787+
// Prefer the actual challenge widget (the box holding the Turnstile checkbox input);
788+
// fall back to the first content div for older challenge layouts.
789+
const div =
790+
document.querySelector('.main-content div:has(input[id^="cf-chl-widget-"])') ??
791+
document.querySelector('.main-content div');
786792
return div?.getBoundingClientRect();
787793
})
788794
.catch(() => undefined);

test/e2e/camoufox-cloudflare/actor/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ await Actor.main(async () => {
2828
async requestHandler({ page, parseWithCheerio }) {
2929
const isBlocked = await page
3030
.evaluate(async () => {
31-
return !!document.querySelector('.footer > .footer-inner > .diagnostic-wrapper > .ray-id');
31+
return !!document.querySelector('.footer .footer-inner .diagnostic-wrapper .ray-id');
3232
})
3333
.catch(() => false);
3434
const $ = await parseWithCheerio();

test/e2e/camoufox-cloudflare/actor/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
"@crawlee/playwright": "file:./packages/playwright-crawler",
1414
"@crawlee/types": "file:./packages/types",
1515
"@crawlee/utils": "file:./packages/utils",
16-
"camoufox-js": "^0.9.3",
17-
"playwright": "1.58.2"
16+
"camoufox-js": "^0.11.0",
17+
"playwright": "1.60.0"
1818
},
1919
"overrides": {
2020
"apify": {

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ __metadata:
11411141
apify-node-curl-impersonate: "npm:^1.0.15"
11421142
basic-auth-parser: "npm:^0.0.2"
11431143
body-parser: "npm:^2.0.0"
1144-
camoufox-js: "npm:^0.10.0"
1144+
camoufox-js: "npm:^0.11.0"
11451145
commitlint: "npm:^21.0.0"
11461146
cross-env: "npm:^10.0.0"
11471147
deep-equal: "npm:^2.0.5"
@@ -4401,14 +4401,14 @@ __metadata:
44014401
languageName: node
44024402
linkType: hard
44034403

4404-
"better-sqlite3@npm:^12.2.0":
4405-
version: 12.4.1
4406-
resolution: "better-sqlite3@npm:12.4.1"
4404+
"better-sqlite3@npm:^12.10.0":
4405+
version: 12.10.0
4406+
resolution: "better-sqlite3@npm:12.10.0"
44074407
dependencies:
44084408
bindings: "npm:^1.5.0"
44094409
node-gyp: "npm:latest"
44104410
prebuild-install: "npm:^7.1.1"
4411-
checksum: 10c0/88773a75d996b4171e5690a38459b05dc814a792701b224bd9909ee084dc0b4c64aaffbdbcf4bbbc6d4e247faf19e91b2a56cf4175d746d3bd9ff14764eb05aa
4411+
checksum: 10c0/b269792c1e456201b16fb9abd1e3fa9284d7710929f991899cebbb61e56dc3703673be29dadcb2f4a2d02961c49145f53d7d7b13b7b47298c033ec9de524f34f
44124412
languageName: node
44134413
linkType: hard
44144414

@@ -4764,12 +4764,12 @@ __metadata:
47644764
languageName: node
47654765
linkType: hard
47664766

4767-
"camoufox-js@npm:^0.10.0":
4768-
version: 0.10.2
4769-
resolution: "camoufox-js@npm:0.10.2"
4767+
"camoufox-js@npm:^0.11.0":
4768+
version: 0.11.0
4769+
resolution: "camoufox-js@npm:0.11.0"
47704770
dependencies:
47714771
adm-zip: "npm:^0.5.16"
4772-
better-sqlite3: "npm:^12.2.0"
4772+
better-sqlite3: "npm:^12.10.0"
47734773
cli-progress: "npm:^3.12.0"
47744774
commander: "npm:^14.0.0"
47754775
fingerprint-generator: "npm:^2.1.66"
@@ -4784,7 +4784,7 @@ __metadata:
47844784
playwright-core: "*"
47854785
bin:
47864786
camoufox-js: dist/__main__.js
4787-
checksum: 10c0/f04cd3b46f507649d7d2c882ad5f9e1a3a4420480d5a196b40d26ca635d2d2193764625fa6518baa17a2283445a689194aa2139c67825f1326604870859f7890
4787+
checksum: 10c0/ac17d937edd690133638568e34726fe5b60ce763d6252edf163e6326571de7263d6103facd5fb3a7ca6979d7339aad454c588eef945676e96a8083d06c884165
47884788
languageName: node
47894789
linkType: hard
47904790

0 commit comments

Comments
 (0)