Solve reCAPTCHA with JavaScript: A Complete Tutorial

Emma Foster
Machine Learning Engineer
20-Aug-2024

While reCAPTCHA effectively safeguards web content, it can sometimes hinder legitimate activities, such as research, data analysis, or other compliance-driven automation tasks that involve interacting with web services.
What You Will Learn
So in this blog, we will walk you through the steps needed to solve reCAPTCHA challenges using JavaScript. You’ll learn how to set up your development environment, use Puppeteer to interact with web pages, and implement solutions for both reCAPTCHA v2 and v3. By the end of this tutorial, you’ll have a strong understanding of how to programmatically solve reCAPTCHA challenges, allowing you to integrate this knowledge into your own projects.
What is reCAPTCHA ?
reCAPTCHA is a type of CAPTCHA that helps distinguish human users from bots by presenting challenges that are simple for humans but difficult for machines. Over the years, reCAPTCHA has evolved from distorted text that users need to type in, to more complex image-based puzzles, and now to an almost invisible version that runs in the background, scoring users based on their behavior on the site.
Redeem Your CapSolver Bonus Code
Boost your automation budget instantly!
Use bonus code CAPN when topping up your CapSolver account to get an extra 5% bonus on every recharge — with no limits.
Redeem it now in your CapSolver Dashboard
.
Versions of reCAPTCHA:
-
reCAPTCHA v2: This version is widely recognized for its "I'm not a robot" checkbox and image-based challenges. It requires users to click on images or verify certain actions, making it effective for distinguishing humans from bots.

-
reCAPTCHA v3: Unlike v2, reCAPTCHA v3 is invisible and works in the background. It assesses users' interactions on a website and assigns a score based on how likely it is that the user is a bot. Websites can then use this score to decide whether to allow or block the user.
-
reCAPTCHA Enterprise: For businesses with higher security needs, reCAPTCHA Enterprise showing up. This version provides advanced protection against sophisticated threats, integrating more deeply with enterprise-level security measures. It includes enhanced risk analysis, customizable scoring, and better scalability, making it suitable for organizations handling sensitive data or critical operations.

Why Solve reCAPTCHA with JavaScript?
For developers working on projects like web scraping, automated testing, or form automation, encountering reCAPTCHA can be a significant roadblock. Manually solving reCAPTCHA every time is not feasible in automation scenarios, which is where JavaScript comes into play. By leveraging JavaScript, specifically with the help of tools like Puppeteer, developers can programmatically interact with and solve reCAPTCHA challenges.
Common Use Cases:
1. Web Scraping: Extracting data from websites often involves interacting with forms or pages protected by reCAPTCHA.
2. Automated Testing: Ensuring the stability of web applications may require automated form submissions or interactions with CAPTCHA-protected pages.
3. Form Automation: Automating repetitive tasks, such as filling out and submitting forms, often needs bypassing CAPTCHA to complete the workflow.
Prerequisites
Before we dive into the code, there are a few prerequisites you should have in place to follow along with this tutorial successfully:
- Basic Understanding of JavaScript: This tutorial assumes you have a basic knowledge of JavaScript, including familiarity with concepts like variables, functions, and asynchronous programming.
- Node.js and npm: We will be using Node.js, a JavaScript runtime, along with npm (Node Package Manager) to manage our project’s dependencies. If you don’t have Node.js installed, you can download it from the official Node.js website.
- CapSolver API Key: To effectively solve reCAPTCHA challenges, you'll need access to a service like CapSolver, which specializes in solving CAPTCHA challenges programmatically. Make sure you sign up and obtain an API key from CapSolver to integrate it into your solution.
Once you’ve met these prerequisites, you’re ready to set up your environment and start solving reCAPTCHA challenges with JavaScript and CapSolver.
Steps to Solve reCAPTCHA with JavaScript
Obtaining the Site Key
- In the browser’s request logs, search for the request
/recaptcha/api2/reload?k=6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-, where the value afterk=is the Site Key we need. Or you can find all the paramters to solve recapctha through CapSolver extension - The URL is the address of the page that triggers the reCAPTCHA V2.
Install the requests library
bash
pip install requests
Example code
python
import requests
import time
from DrissionPage import ChromiumPage
# Create an instance of ChromiumPage
page = ChromiumPage()
# Access the example page that triggers reCAPTCHA
page.get("https://www.google.com/recaptcha/api2/demo")
# TODO: Set your configuration
api_key = "your api key of capsolver" # Your CapSolver API key
site_key = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-" # Site key of your target site
site_url = "https://www.google.com/recaptcha/api2/demo" # Page URL of your target site
def capsolver():
payload = {
"clientKey": api_key,
"task": {
"type": 'ReCaptchaV2TaskProxyLess',
"websiteKey": site_key,
"websiteURL": site_url
}
}
# Send a request to CapSolver to create a task
res = requests.post("https://api.capsolver.com/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
print("Failed to create task:", res.text)
return
print(f"Got taskId: {task_id} / Getting result...")
while True:
time.sleep(3) # Delay
payload = {"clientKey": api_key, "taskId": task_id}
# Query task results
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
return resp.get("solution", {}).get('gRecaptchaResponse')
if status == "failed" or resp.get("errorId"):
print("Solve failed! response:", res.text)
return
def check():
# Get the reCAPTCHA solution
token = capsolver()
# Set the reCAPTCHA response value
page.run_js(f'document.getElementById("g-recaptcha-response").value="{token}"')
# Call the success callback function
page.run_js(f'onSuccess("{token}")')
# Submit the form
page.ele('x://input[@id="recaptcha-demo-submit"]').click()
if __name__ == '__main__':
check()
Explanation:
- Obtaining the Site Key: Look for the request containing the
k=parameter in the browser’s request logs, and extract the value followingk=as the Site Key. - Set the configuration: Replace
api_key,site_key, andsite_urlin the code with your actual values. - Execute the code: By calling the
check()function, the code will automatically retrieve the reCAPTCHA solution and submit the form.
Make sure to comply with the terms of service and legal regulations of the websites you interact with.
Conclusion
Solving reCAPTCHA challenges programmatically with JavaScript offers a powerful solution for automating tasks that involve interacting with web services protected by CAPTCHA. By leveraging tools like Puppeteer and CapSolver, you can effectively bypass these challenges, streamline your workflows, and integrate automated solutions into your projects.
As reCAPTCHA continues to evolve, staying informed about its different versions and utilizing appropriate strategies becomes crucial. Whether you're tackling web scraping, automated testing, or form automation, understanding how to manage reCAPTCHA efficiently can greatly enhance your productivity and accuracy.
Remember, while automation can significantly boost efficiency, it's essential to respect the terms of service of the websites you engage with and ensure compliance with legal standards. With the right tools and knowledge, you can navigate the complexities of reCAPTCHA and focus on what truly matters in your development efforts.
Note on Compliance
Important: When engaging in web scraping, it's crucial to adhere to legal and ethical guidelines. Always ensure that you have permission to scrape the target website, and respect the site's
robots.txtfile and terms of service. CapSolver firmly opposes the misuse of our services for any non-compliant activities. Misuse of automated tools to bypass CAPTCHAs without proper authorization can lead to legal consequences. Make sure your scraping activities are compliant with all applicable lcaptcha and regulations to avoid potential issues.
FAQ
1. Is it legal to solve reCAPTCHA programmatically using tools like CapSolver?
Using automation tools to solve reCAPTCHA is legal only when performed with proper authorization and in compliance with the target website’s terms of service.
Activities such as research, QA testing, or internal automation are typically acceptable.
However, using CAPTCHA-solving services for unauthorized scraping, spam, or evading security controls is strictly prohibited and may lead to legal consequences.
Always ensure your automation aligns with ethical and legal guidelines.
2. Why do I need JavaScript or Puppeteer to solve reCAPTCHA instead of regular HTTP requests?
reCAPTCHA v2, v3, and Enterprise rely on multiple factors beyond a simple token, including:
- Browser fingerprinting
- JavaScript execution
- User interaction patterns
- Cookies and DOM behavior
- Risk scoring (especially for v3 and Enterprise)
A plain HTTP request cannot simulate this environment.
Puppeteer (or similar browser automation tools) creates a realistic browser context, making it possible to handle reCAPTCHA challenges successfully and reliably.
3. I obtained a token from CapSolver, but the form does not submit. What could be wrong?
Several factors can prevent a reCAPTCHA bypass from working correctly:
Common causes:
- Incorrect or outdated SiteKey
- Wrong websiteURL passed to CapSolver
- Token inserted into the wrong DOM element
- Missing callback execution (e.g.,
onSuccess()not triggered) - JavaScript on the page expecting additional user actions
- Page using Enterprise reCAPTCHA (requires a different task type)
Recommended checks:
- Confirm your
site_keyandsite_urlmatch the actual values from the page. - Ensure the token is correctly inserted into the
g-recaptcha-responsefield. - Trigger the site’s success callback manually, if required.
- If the site uses Enterprise, switch to
ReCaptchaEnterpriseTaskProxyLess. - Review browser logs for JavaScript errors that may stop form submission.
Compliance Disclaimer: The information provided on this blog is for informational purposes only. CapSolver is committed to compliance with all applicable laws and regulations. The use of the CapSolver network for illegal, fraudulent, or abusive activities is strictly prohibited and will be investigated. Our captcha-solving solutions enhance user experience while ensuring 100% compliance in helping solve captcha difficulties during public data crawling. We encourage responsible use of our services. For more information, please visit our Terms of Service and Privacy Policy.
More

How to Identify and Obtain reCAPTCHA “s” Parameter Data
Learn to identify and obtain reCaptcha 's' data for effective captcha solving. Follow our step-by-step guide on using Capsolver's tools and techniques.

Ethan Collins
25-Nov-2025

How to Identify and Submit reCAPTCHA Extra Parameters (v2/v3/Enterprise) | CapSolver Guide
Learn how to detect and submit extra reCAPTCHA parameters using CapSolver to improve accuracy and solve complex challenges.

Rajinder Singh
10-Nov-2025

How to Solve reCAPTCHA When Scraping Search Results with Puppeteer
Master the art of Puppeteer web scraping by learning how to reliably solve reCAPTCHA v2 and v3. Discover the best puppeteer recaptcha solver techniques for large-scale data harvesting and SEO automation.

Lucas Mitchell
04-Nov-2025

AI Powered SEO Automation: How to Solve Captcha for Smarter SERP Data Collection
Discover how AI Powered SEO Automation overcomes CAPTCHA challenges for smarter SERP data collection and learn about reCAPTCHA v2/v3 solutions

Emma Foster
23-Oct-2025

reCAPTCHA Solver Auto Recognition and Solve Methods
Learn how to automatically recognize and solve Google reCAPTCHA v2, v3, invisible, and enterprise challenges using advanced AI and OCR techniques

Sora Fujimoto
22-Oct-2025

How to Solve reCAPTCHA v2: Solve reCAPTCHA v2 Guide
Learn how to automate solving Google reCAPTCHA v2 using CapSolver. Discover API and SDK integration, step-by-step guides, and bonus codes to streamline captcha solving for web scraping, automation, and development projects.

Aloísio Vítor
21-Oct-2025


.