captcha():
- Finds the captcha on the page and reads its sitekey.
- Sends it to 2captcha and waits for the solution.
- Puts the token into the page and calls the page’s captcha callbacks.
- Clicks the form’s submit button.
provision.chrome().
Signature
Parameters
CaptchaOptions
required
Captchas it detects
Returns
object
Errors
captcha() throws when:
apiKeyis missing.- No captcha is found on the page and you didn’t set
sitekey. The message isCould not auto-detect captcha. Please provide sitekey manually. - The solver reports an error, for example a 2captcha error or a timeout. The message starts with
[captcha].
Examples
Solve a captcha before submitting a form
tests/signup.test.mjs
Submit the form yourself
Set the sitekey and type
Set up the API key
Sign up at 2captcha.com, add funds, and copy your API key. Keep it out of your test code: put it in.env locally, and in a secret in CI.
.env
.github/workflows/testdriver.yml
Troubleshooting
Could not auto-detect captcha
Could not auto-detect captcha
The captcha wasn’t on the page when
captcha() ran. Wait for it to load first, for example with find() and a timeout. If it still isn’t detected, pass sitekey and type.The solve times out
The solve times out
2captcha’s workers usually take 10 to 30 seconds. Raise
timeout, and check that your 2captcha account has funds.The site rejects the token
The site rejects the token
Check that
type matches the captcha on the page. For reCAPTCHA v3, check that action matches the action the site uses.Related
- Launch apps: open Chrome before solving
- Secrets: keep API keys out of your tests
- type() and find(): fill in the rest of the form

