Solving reCAPTCHA v2 with PuppeteerSharp and DeathByCaptcha in C#

Solving reCAPTCHA v2 with PuppeteerSharp and DeathByCaptcha in C#

Posted on 2026-11-20 | 3 min read | Category: puppeteer | By DeathByCaptcha Engineering Team

Puppeteer


Solving reCAPTCHA v2 with PuppeteerSharp and DeathByCaptcha in C

Puppeteer is a Node.js library, so C# teams use PuppeteerSharp, a community port that tracks the same API. The captcha problem does not change: the browser can fill the form, but the token has to come from somewhere.

This example opens Google's reCAPTCHA v2 demo with PuppeteerSharp, reads the sitekey, requests a token from DeathByCaptcha, injects it and submits the form. The token is never printed.

The example lives in the official .NET client:

  • DBC_Examples/PuppeteerRecaptchaV2Example.cs

What you need

  • .NET SDK that supports net8.0 or net10.0. PuppeteerSharp does not ship a net6.0 build, so the sample and its test are excluded from that target.
  • Chrome. The sample uses CHROME_BIN when it points to an existing browser and otherwise downloads Chrome for Testing through PuppeteerSharp.
  • A DeathByCaptcha account with balance.

Credentials

Set the variables in the environment or in a .env file at the repository root:

DBC_USERNAME=your_username
DBC_PASSWORD=your_password

The sample never prints the token and never enables verbose output.

Run it

dotnet run --project DBC_Examples/DBC_Examples.csproj -c Release -f net10.0 \
  -p:ExamplesStartupObject=DeathByCaptcha.PuppeteerRecaptchaV2Example

--headed shows the browser; headless is the default. A URL argument replaces the demo page.

The flow

Launch the browser, resolve Chrome and open the demo:

string chromePath = await ResolveChromePathAsync();

await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = headless,
    ExecutablePath = chromePath,
    Args = new[] { "--no-sandbox", "--disable-dev-shm-usage" },
});

await using var page = await browser.NewPageAsync();
await page.GoToAsync(pageUrl, new NavigationOptions { Timeout = 60000 });
await page.WaitForSelectorAsync("#recaptcha-demo",
    new WaitForSelectorOptions { Timeout = 20000 });

Read the sitekey and request a type 4 token:

string sitekey = await page.EvaluateFunctionAsync<string>(
    "() => document.querySelector('#recaptcha-demo').getAttribute('data-sitekey')");

string tokenParams = JsonSerializer.Serialize(new Dictionary<string, string>
{
    ["googlekey"] = sitekey,
    ["pageurl"] = pageUrl,
});

var captchaData = new Hashtable
{
    ["type"] = 4,
    ["token_params"] = tokenParams,
};

Client client = new HttpClient(username, password);
Captcha solution = client.Decode(Client.DefaultTokenTimeout, captchaData);

Inject the token as a function argument, fire the events and call the widget callback when the page exposes it:

await page.EvaluateFunctionAsync<bool>(
    @"(token) => {
        const textarea = document.getElementsByName('g-recaptcha-response')[0]
            || document.getElementById('g-recaptcha-response');
        if (!textarea) return false;

        textarea.style.display = 'block';
        textarea.value = token;
        textarea.dispatchEvent(new Event('input', { bubbles: true }));
        textarea.dispatchEvent(new Event('change', { bubbles: true }));

        const clients = window.___grecaptcha_cfg && window.___grecaptcha_cfg.clients;
        // ... call the first callback found ...
        return true;
    }",
    solution.Text);

Then submit and wait for the success selector.

Why the callback matters

Filling the hidden field is not always enough. Many forms keep the submit button disabled until the widget callback runs. The sample walks ___grecaptcha_cfg.clients and calls the first callback it finds, which is what the browser would have done after a human solved the challenge.

The sample also checks that the token was actually written to the field. A form submitted with an empty token is a silent failure; the example prefers to stop and say so.

Things to know

  • PuppeteerSharp is a port, not Puppeteer. It is actively maintained and tracks the upstream API, but it is not published by the Puppeteer team. Name it correctly in your own documentation.
  • The sample uses Google's demo page. It is the vendor's own test page. Do not point it at a site you do not own or have permission to test.
  • IP-bound types need a proxy. Turnstile, WAF and DataDome tokens are tied to the exit IP; the browser and the service must share it.
  • Verbose is off by default. The client used to print every request and response, including the solved token. Now it only does so when the caller enables it.
  • CI runs the same flow. The repository runs the sample as an xUnit test on every push, with the account secrets in GitHub.

Next steps

The same call shape works for the other token types: change the type and the parameter key (token_params, turnstile_params, waf_params). The repository has per-type examples and a Playwright sample with the same injection pattern.

  • .NET client: https://github.com/deathbycaptcha/deathbycaptcha-api-client-dotnet
  • 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
  • 4 seconds - Normal CAPTCHAs (1 min. ago)
  • 7 seconds - reCAPTCHA V2, V3 (1 min. ago)
  • 5 seconds - others (1 min. ago)
Chrome and Firefox logos
Browser extensions available

Updates

  1. Nov 19: We are currently updating our cryptocurrency payment processor, Hekelet, so crypto payments may be temporarily unavailable. In the meantime, you can purchase credits through 2Checkout or contact our support team for assistance. We expect normal crypto payment processing to be restored within this week. Thank you for your patience and understanding!
  2. 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.
  3. Apr 15: GitHub Updates: We’ve upgraded our libraries, expanded sample code, enhanced documentation, and added support for C++ and Go, making integration smoother than ever. Explore what’s new at github.com/deathbycaptcha!

  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