Skip to main content
Version: Next

handleCloudflareChallengeHook

Callable


  • Returns a postNavigationHooks-ready hook that runs PlaywrightContextUtils.handleCloudflareChallenge and propagates the post-challenge Response back into the crawling context via its return value.

    Cloudflare serves its challenge pages with a 403 status, which is part of the default blockedStatusCodes. Keep it there - the hook runs before the blocked-status check and replaces the response on a solved challenge, so solved requests pass it, while unsolved or undetected challenges keep the 403 and get retried with a fresh session.

    Example usage

    import { PlaywrightCrawler, handleCloudflareChallengeHook } from 'crawlee';

    const crawler = new PlaywrightCrawler({
    postNavigationHooks: [handleCloudflareChallengeHook()],
    });

    Parameters

    Returns PlaywrightHook