CAPTCHA is a general term for challenges that verify you’re human. This includes reCAPTCHA, hCaptcha, Cloudflare Turnstile, and similar services.
Available helpers
waitForCaptchaSolve— Wait for a CAPTCHA to be solvedwithWaitForCaptchaSolve— Execute a callback then wait for CAPTCHA solveonCaptchaEvent— Register a callback for CAPTCHA updatesonceCaptchaEvent— Register a one-time callback for a CAPTCHA updateremoveCaptchaEventListener— Remove a previously registered callback
Function reference
waitForCaptchaSolve
Parameters
Playwright page object.
Configuration options for the wait behavior.
Maximum wait time in milliseconds. Throws
TimeoutError if exceeded.Wait time in milliseconds before checking if CAPTCHAs appeared. Resets when a CAPTCHA is detected during the period.
Returns Returns
Promise<void> when solved or settle period elapses.
Raises
TimeoutError— Thrown whentimeoutInMselapses while CAPTCHAs are still being solved.CaptchaSolveError— Thrown when the CAPTCHA solver fails. Contains aCaptchaErrorwith the error code and details.Error— Thrown when listeners cannot be attached or the page context is invalid.
withWaitForCaptchaSolve
Parameters
Function to execute before waiting for solve. Receives the page object and can return a value.
Configuration options for the wait behavior.
Playwright page object.
Maximum wait time in milliseconds. Throws
TimeoutError if exceeded.Wait time in milliseconds before checking if CAPTCHAs appeared. Resets when a CAPTCHA is detected during the period.
Whether to wait for network idle before checking solve status.
Returns Returns
Promise<T> with the result of the callback function.
Raises
TimeoutError— Thrown whentimeoutInMselapses while CAPTCHAs are still being solved.CaptchaSolveError— Thrown when the CAPTCHA solver fails. Contains aCaptchaErrorwith the error code and details.Error— Thrown if something unexpected happens.
onCaptchaEvent
Parameters
Playwright page object.
The CAPTCHA status to listen for.
Callback function that executes when the status is observed. Receives a
Captcha object as its only argument.Returns Returns
Promise<void>. The function subscribes and resolves immediately. The callback fires each time a CAPTCHA with the specified status is observed.
Raises
RuntimeError— Thrown when listeners cannot be attached or the page context is invalid.
onceCaptchaEvent
Parameters
Playwright page object.
The CAPTCHA status to listen for.
Callback function that executes when the status is observed. Receives a
Captcha object as its only argument.Returns Returns
Promise<void>. The function subscribes and resolves immediately. The callback fires at most once.
Raises
RuntimeError— Thrown when listeners cannot be attached or the page context is invalid.
removeCaptchaEventListener
onCaptchaEvent or onceCaptchaEvent. You must pass the same page, status, and callback function that were used to register the callback.
Parameters
Playwright page object.
The CAPTCHA status that the listener was registered for.
The callback function that was originally registered. Must be the same function reference.
Returns Returns
Promise<void>. The function unsubscribes the callback and resolves immediately.
Raises
RuntimeError— Thrown when the callback cannot be removed or the page context is invalid.
onceCaptchaEvent are automatically removed after firing.
Best practices
- Use
waitForCaptchaSolvefor most cases where you need to wait for solve completion. - Set appropriate timeout values based on CAPTCHA complexity (15-30 seconds typical).
- Adjust the settle duration for the wait before checking status. Resets when CAPTCHAs are detected.
- Enable
waitForNetworkSettledto wait for network idle before checking solve status. - Subscribe to CAPTCHA updates using
onCaptchaEventoronceCaptchaEventfor telemetry and monitoring. - Store callback function references if you need to unsubscribe later.
Type reference
Captcha
Unique identifier for the CAPTCHA observation.
Browser tab ID where the CAPTCHA was detected.
CAPTCHA provider type, such as
recaptcha, hcaptcha, or cloudflare.Current solving state.
Number of solve attempts made.
error
Error details when
status is error, otherwise undefined.CaptchaStatus
attached— CAPTCHA element detected in the page. Use this to know when a challenge appears.solving— Solver is actively processing the CAPTCHA.solved— CAPTCHA solved successfully. Resume your workflow.error— Solver failed. Check theerrorfield for details.detached— CAPTCHA element removed from the page. Treat as cancelled.
CaptchaError
Error code indicating the type of failure.
Additional error details, if available.
CaptchaErrorCode
HIT_LIMIT— Reached billing limits for CAPTCHA solves. See Plans and billing for details on limits and upgrading.MAX_RETRIES— Exceeded maximum retry attempts specified insettings.maxRetries.UNEXPECTED_ERROR— An unexpected error occurred while solving. This is a solver error and not related to your automation.UNEXPECTED_SERVER_RESPONSE— The solver received an unexpected response. This is a solver error and not related to your automation.