Solve hCaptcha in Puppeteer
Puppeteer is the same idea as Playwright. The VanishCaptcha npm client returns the token; page.evaluate writes it into the widget.
Steps
- Open the page and read data-sitekey.
- Call solve() with that sitekey and page.url().
- Fill the response fields, then click the site’s own submit button.
node
import puppeteer from "puppeteer"; import { VanishCaptcha } from "vanishcaptcha"; const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto("https://example.com/login"); const sitekey = await page.$eval("[data-sitekey]", (el) => el.getAttribute("data-sitekey")); const solve = await new VanishCaptcha({ apiKey: process.env.VANISHCAPTCHA_KEY }).solve({ type: "hcaptcha", sitekey, url: page.url(), }); await page.evaluate((token) => { for (const name of ["h-captcha-response", "g-recaptcha-response"]) { const el = document.querySelector(`[name="${name}"]`); if (el) el.value = token; } }, solve.token);
Enterprise rqdata
If the widget carries rqdata, send type: "hcaptcha_enterprise" and that value. The token that comes back is what the enterprise sitekey expects. Fields are in the API reference.
Questions
Does this solve reCAPTCHA or Turnstile?
No. These guides are hCaptcha only. reCAPTCHA and Turnstile are not live on VanishCaptcha.
How long is the token good for?
About two minutes, and it can be submitted once. Request it immediately before the form goes out.