Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@
"oxfmt --write --no-error-on-unmatched-pattern"
]
},
"packageManager": "pnpm@11.22.0",
"packageManager": "pnpm@12.8.1",
"devEngines": {
"packageManager": {
"name": "pnpm",
"version": "11.22.0",
"version": "12.8.1",
"onFail": "error"
}
},
"volta": {
"node": "24.18.0",
"pnpm": "11.22.0"
"pnpm": "12.8.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,11 @@ export async function handleCloudflareChallenge(

// check if we ended up on the CF challenge page
const isChallenge = async () => {
return options.isChallengeCallback!(page).catch(() => false);
return options.isChallengeCallback!(page).catch(async () => {
// the challenge page navigates itself, which destroys the context of an in-flight check
await page.waitForLoadState('domcontentloaded').catch(() => {});
return options.isChallengeCallback!(page).catch(() => false);
});
};

if (!(await isChallenge())) {
Expand Down
199 changes: 79 additions & 120 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions test/core/playwright_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from 'node:path';

import { MemoryStorageBackend, serviceLocator } from '@crawlee/core';
import { KeyValueStore, launchPlaywright, playwrightUtils, Request } from '@crawlee/playwright';
import { sleep } from '@crawlee/utils';
import type { Browser, Page } from 'playwright';
import { chromium } from 'playwright';
import { runExampleComServer } from '../shared/_helper.js';
Expand Down Expand Up @@ -495,6 +496,41 @@ describe('playwrightUtils', () => {
);
});

test('detects the challenge when the challenge page navigates itself during the check', async () => {
const url = 'https://challenge.test/';
await page.route(`${url}**`, async (route) => {
if (!route.request().url().includes('__cf_chl_tk')) {
// keeps the check busy until the navigation below commits and destroys its execution context
await route.fulfill({
contentType: 'text/html',
body: `<html><body>${currentChallengeBody}<script>
window.addEventListener('load', () => setTimeout(() => { location.href = '/?__cf_chl_tk=1'; }));
const querySelector = document.querySelector.bind(document);
document.querySelector = (selector) => {
const end = Date.now() + 1000;
while (Date.now() < end) {}
return querySelector(selector);
};
</script></body></html>`,
});
return;
}

await sleep(200);
await route.fulfill({
contentType: 'text/html',
body: `<html><body>${currentChallengeBody}</body></html>`,
});
});

const selfNavigation = page.waitForRequest((request) => request.url().includes('__cf_chl_tk'));
await page.goto(url);
await selfNavigation;

await expect(handleCloudflareChallenge(page, url, fastOptions())).rejects.toThrow(/Blocked by Cloudflare/);
await page.unrouteAll();
});

test('resolves without detection on a regular page', async () => {
await page.setContent('<html><body><h1>Welcome</h1></body></html>');
await expect(
Expand Down
6 changes: 3 additions & 3 deletions website/versioned_docs/version-3.17/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ __metadata:
linkType: hard

"brace-expansion@npm:^1.1.7":
version: 1.1.18
resolution: "brace-expansion@npm:1.1.18"
version: 1.1.21
resolution: "brace-expansion@npm:1.1.21"
dependencies:
balanced-match: "npm:^1.0.0"
concat-map: "npm:0.0.1"
checksum: 10c0/3432c18a9e2ebf94162d4effb62198bd0adea06a9f332b2c0188df5d5e30b1e51ea3c848b6608e47d0b857ebe1ea5b3888ed3326dd3c4f6f9645c94153cf9c14
checksum: 10c0/8f0a68a720f9cb28c2ecaea5cdaf15fafd686d6b6e4e722a81c9d4bd2f68c1fd0619731cac05875d842221eaf4d97d564d329a12eb3c4c22137502fb3c65be8b
languageName: node
linkType: hard

Expand Down
Loading