Solve CAPTCHAs in Crawlee crawlers with DeathByCaptcha

Solve CAPTCHAs in Crawlee crawlers with DeathByCaptcha

Posted on 2026-12-03 | 6 min read | Category: captcha-automation | By DeathByCaptcha Engineering Team

CAPTCHA Automation


Solve CAPTCHAs in Crawlee crawlers with DeathByCaptcha

A Crawlee crawl that stops at a protected form is not a failed crawl, it is a crawl that never reached the data. The fix is a navigation hook that asks DeathByCaptcha for the answer and hands it to the page before the handler reads anything.

Where the solve happens

Crawlee runs two hooks around every navigation, and its own documentation marks the post-navigation hook as the place for CAPTCHA checks: the page is loaded and the widget, if there is one, is in the DOM. That is the whole design of this example —

  • the pre-navigation hook keeps the run fast: block_requests() stops images, styles and fonts from loading, and the challenge script still does;
  • the post-navigation hook detects the widget, reads its data-sitekey, asks for a token, writes it into the page and submits;
  • the request handler waits for the success state and pushes the outcome to the dataset.

The solve runs in the worker, never in the browser: the credentials never reach the page and the token is returned as a value, so it stays out of the log. Nothing is published as an npm package or on PyPI. The example is a folder you copy.

Files

File What it is
examples/crawlee/deathbycaptcha.solve.js (Node) / solver.py (Python) the solvers: promises or plain functions over the official client, testable without a browser
examples/crawlee/crawler.js / crawler.py the Crawlee cookbook: a PlaywrightCrawler with the hooks and the handler
examples/crawlee/README.md setup, hooks and limits

The hooks

Hook What it does
preNavigationHooks / pre_navigation_hook block_requests() — no images, styles or fonts; the challenge script still loads
postNavigationHooks / post_navigation_hook the CAPTCHA walk: detect #recaptcha-demo, read data-sitekey, solve, inject, submit
requestHandler / request_handler waits for .recaptcha-success, pushes the outcome and prints CRAWL_OK

The post-navigation hook in the Node crawler:

postNavigationHooks: [
  async ({ page, request, log }) => {
    const widget = await page.$('#recaptcha-demo');
    if (!widget) {
      // No challenge on this page: nothing to solve, keep crawling.
      return;
    }

    const sitekey = await widget.getAttribute('data-sitekey');
    const pageurl = request.url;
    let token = solved.get(pageurl);

    if (!token) {
      log.info(`Solving the challenge for ${pageurl}`);
      token = await solver.recaptchaV2({ sitekey, pageurl });
      solved.set(pageurl, token);
    }

    await page.evaluate(INJECT_TOKEN, token);
    await page.click('#recaptcha-demo-submit');
    log.info('Token injected, form submitted');
  },
],

The Python hook is the same walk with two differences that matter:

if token is None:
    context.log.info("Solving the challenge for %s", pageurl)
    # The client blocks while it polls: keep it off the event
    # loop so the crawler keeps serving the browser.
    token = await asyncio.to_thread(
        dbc.solve_recaptcha_v2, sitekey, pageurl
    )
    SOLVED[pageurl] = token

The official Python client is synchronous: a solve inside the hook would freeze the crawler's event loop for up to two minutes while the browser waits. asyncio.to_thread keeps both running. The Node client is callback-based, so its promise slots into the async hook without extra work.

Setup

# Node.js
npm install deathbycaptcha-lib crawlee
# Python
pip install deathbycaptcha-official
pip install -r examples/crawlee/requirements.txt

export DBC_USERNAME=your_username
export DBC_PASSWORD=your_password
# or: export DBC_AUTHTOKEN=your_authtoken

The Node example runs on Crawlee v3 (version 4 requires Node 22.15 and the repository supports Node 20); the Python example runs on Crawlee v1 for Python 3.10 or newer, and needs Playwright's Chromium once:

playwright install chromium

Run

node examples/crawlee/crawler.js
python examples/crawlee/crawler.py

The crawler writes its storage (datasets, request queues) under the current working directory; point CRAWLEE_STORAGE_DIR somewhere else to keep it out of a project.

The two balance guards

A crawl retries failed requests — Crawlee does it three times by default — and every retry would buy the same solve again. The example closes both doors:

  • One token per URL. The solved map is keyed by page: a retried request re-injects the token it already bought instead of paying for the same solve twice.
  • max_requestRetries: 1 / max_request_retries=1. A failed solve must not burn the balance on three more attempts.

The sandbox that stops CI

The first continuous-integration run of the Python example failed with "Chromium sandboxing failed": the JavaScript crawler turns the Chromium sandbox off by default, and the Python crawler leaves it on, which a CI container rarely supports. The example launches the same way as the JavaScript one:

browser_launch_options={"chromium_sandbox": False},

If your own runner has a working sandbox, delete the line and keep the protection.

What the crawler does

  1. Visits Google's reCAPTCHA demo — the vendor's own page, not a third party's production site.
  2. The pre-navigation hook blocks the static assets.
  3. The post-navigation hook reads the data-sitekey from the page instead of typing it in and asks for a token.
  4. It writes the token into #g-recaptcha-response and calls the widget's callback — the same walk as the Playwright, Puppeteer, Cypress and WebdriverIO samples in the Node client, and the Selenium and Playwright samples in the Python one.
  5. Submits and waits for .recaptcha-success.

The rule that catches people out

A token answer is valid only from the exit IP that solved it. The solve runs on the machine that runs the crawl, so a solve and the request it is pasted into leave from the same machine — unless your crawl leaves through a proxy, in which case pass the same proxy and proxytype in the parameters. Without them the token is solved from your crawler's address and the site rejects it, which looks like a DeathByCaptcha failure and is not one.

Limits

  • QA on your own pages. These crawls are for flows you are allowed to automate — staging, a demo, a page you own. See RESPONSIBLE_USE.md.
  • reCAPTCHA v3 needs the action and the min_score the site expects; a mismatch is a token the site refuses.
  • HTTP crawlers cannot inject. HttpCrawler has no page: the token is handed to the site as a parameter or a header instead of written into the widget. This example uses PlaywrightCrawler because the widget walk is the part readers need to see.
  • Never print the token: the solvers return it as a value and nothing else should echo it.

Tests

npm run test:unit                                       # solver tests, no network
DBC_USERNAME=... DBC_PASSWORD=... npm run test:integration:crawlee

python -m pytest tests/test_crawlee_solver.py -v        # no network
DBC_TEST_USERNAME=... DBC_TEST_PASSWORD=... python -m pytest tests/test_crawlee_integration.py -v

The unit tests replace the client with a fake. The integration tests run the real crawler in a temporary directory against the live API, check that it reported a verified page and fail if anything in the output looks like a token. Both skip themselves when the credentials are not in the environment, and both run in the continuous integration of their repository on every push.

Next steps

  • Node example: https://github.com/deathbycaptcha/deathbycaptcha-api-client-nodejs
  • Python example: https://github.com/deathbycaptcha/deathbycaptcha-api-client-python
  • API documentation: https://deathbycaptcha.com/api

Common pitfalls

  • Using a CAPTCHA solving service for illegitimate purposes instead of legitimate automation and testing.
  • Hard-coding credentials or API keys in client-side code that users can inspect.
  • Sending the wrong CAPTCHA type parameter, which returns incorrect or empty responses.
  • Failing to poll for the solution status and not handling timeouts gracefully.
  • Scaling automation without monitoring error rates, response times, and CAPTCHA type coverage.
DBC
Written by DeathByCaptcha Engineering Team
DeathByCaptcha engineers build and operate the CAPTCHA solving technology behind this site. Articles are written by our technical team and checked for accuracy before publishing.
Reviewed by DeathByCaptcha Editorial Team

Get your API key — start solving

Free to try · No credit card · Python, Node.js, Java, C# SDKs

Get your API key


Status: OK

Servers are fully operational with faster than average response time.
  • Average solving time
  • 1 seconds - Normal CAPTCHAs (1 min. ago)
  • 5 seconds - reCAPTCHA V2, V3 (1 min. ago)
  • 8 seconds - others (1 min. ago)
Chrome and Firefox logos
Browser extensions available

Updates

  1. Dec 01: RESOLVED -The temporary technical issue affecting account registration emails and other automated messages has been resolved, and normal email delivery has been restored. We apologize for any inconvenience this may have caused and appreciate your patience and understanding!
  2. Nov 19: RESOLVED - Crypto payments are now fully operational again through the Hekelet payment processor.
  3. May 13: Crypto payments got better! You can now purchase your CAPTCHAs using cryptocurrency through the Hekelet payment processor at https://deathbycaptcha.com/user-pay and receive an extra 20% FREE CAPTCHA credit with every package purchased this way.

  4. Previous updates…

Support

Our system is designed to be completely user-friendly and easy-to-use. Should you have any trouble with it, simply email us at DBC technical support emailcom, and a support agent will get back to you as soon as possible.

Live Support

Available Monday to Friday (10am to 4pm EST) Live support image. Link to live support page