Blog
How to solve hCaptcha with Node.JS

How to solve hCaptcha with Node.JS

Logo of Capsolver

CapSolver Blogger

How to use capsolver

27-Sep-2023

Solving hCaptcha, hCaptcha with Node.JS, hCaptcha Node.JS solver

⚙️ Prerequisites

  • Proxy (Optional)
  • Node.JS installed
  • Capsolver API key

🤖 Step 1: Install Necessary Packages

Execute the following commands to install the required packages:

npm install axios

👨‍💻 Node.JS Code for solve hCaptcha without proxy

Here's a Node.JS sample script to accomplish the task:

const axios = require('axios');

const PAGE_URL = ""; // Replace with your Website
const SITE_KEY = ""; // Replace with your Website
const CLIENT_KEY = "";  // Replace with your CAPSOLVER API Key

async function createTask(payload) {
  try {
    const res = await axios.post('https://api.capsolver.com/createTask', {
      clientKey: CLIENT_KEY,
      task: payload
    });
    return res.data;
  } catch (error) {
    console.error(error);
  }
}
async function getTaskResult(taskId) {
    try {
        success = false;
        while(success == false){

            await sleep(1000);
        console.log("Getting task result for task ID: " + taskId);
      const res = await axios.post('https://api.capsolver.com/getTaskResult', {
        clientKey: CLIENT_KEY,
        taskId: taskId
      });
      if( res.data.status == "ready") {
        success = true;
        console.log(res.data)
        return res.data;
      }
    }
  
    } catch (error) {
      console.error(error);
      return null;
    }
  }
  

async function solveHCaptcha(pageURL, sitekey) {
  const taskPayload = {
    type: "HCaptchaTaskProxyless",
    websiteURL: pageURL,
    websiteKey: sitekey,
  };
  const taskData = await createTask(taskPayload);
  return await getTaskResult(taskData.taskId);
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
  try {
   
      const response = await solveHCaptcha(PAGE_URL, SITE_KEY );
      console.log(`Received token cookie: ${response.solution.gReCaptcharesponse}`);
        
    }
catch (error) {
    console.error(`Error: ${error}`);
  }

}
main();

👨‍💻 Node.JS Code for solve HCaptcha with proxy

Here's a Node.JS sample script to accomplish the task:

const axios = require('axios');

const PAGE_URL = ""; // Replace with your Website
const SITE_KEY = ""; // Replace with your Website
const CLIENT_KEY = "";  // Replace with your CAPSOLVER API Key
const PROXY =  "https://username:password@host:port";

async function createTask(payload) {
  try {
    const res = await axios.post('https://api.capsolver.com/createTask', {
      clientKey: CLIENT_KEY,
      task: payload
    });
    return res.data;
  } catch (error) {
    console.error(error);
  }
}
async function getTaskResult(taskId) {
    try {
        success = false;
        while(success == false){

            await sleep(1000);
        console.log("Getting task result for task ID: " + taskId);
      const res = await axios.post('https://api.capsolver.com/getTaskResult', {
        clientKey: CLIENT_KEY,
        taskId: taskId
      });
      if( res.data.status == "ready") {
        success = true;
        console.log(res.data)
        return res.data;
      }
    }
  
    } catch (error) {
      console.error(error);
      return null;
    }
  }
  

async function solveHCaptcha(pageURL, sitekey) {
  const taskPayload = {
    type: "HCaptchaTask",
    websiteURL: pageURL,
    websiteKey: sitekey,
    proxy: PROXY
  };
  const taskData = await createTask(taskPayload);
  return await getTaskResult(taskData.taskId);
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}
async function main() {
  try {
   
      const response = await solveHCaptcha(PAGE_URL, SITE_KEY );
      console.log(`Received token cookie: ${response.solution.gReCaptcharesponse}`);
        
    }
catch (error) {
    console.error(`Error: ${error}`);
  }

}
main();

⚠️ Change these variables

  • PROXY: Change to your proxy, only if you use HCaptchaTask.
  • CLIENT_KEY: Obtain your API key from the Capsolver Dashboard.
  • PAGE_URL: Replace with the URL of the website for which you wish to solve hCaptcha
  • SITE_KEY: Replace with the site key of the page with hcaptcha

👀 More information

More

hcaptcha
Announcement Regarding Recent Instability of hCaptcha Service

We apologize for the recent instability of the hCaptcha service caused by image updates.hcaptcha is updated very frequently now, we were keep updating everyday to catch up with the progress.vThere will be some unstable times every day. We deeply regret any inconvenience caused.If you encounter new images that render the service unavailable, please wait for us to update them. If you have any further questions, please feel free to contact us at any time.

hCaptcha

28-Nov-2023

How to solve hCaptcha using Selenium [Javascript] with Capsolver Extension
How to solve hCaptcha using Selenium [Javascript] with Capsolver Extension

Learn to seamlessly solve hCaptcha with Selenium javascript and Capsolver Extension, a detailed guide on setting up and automating captcha solutions effectively

hCaptcha

23-Nov-2023

How identify and obtain hCaptcha rqdata
How identify and obtain hCaptcha rqdata

Learn to identify and obtain hCaptcha rqdata for effective captcha solving. Follow our step-by-step guide on using Capsolver's tools and techniques.

hCaptcha

21-Nov-2023

Làm thế nào để dễ dàng vượt qua bất kỳ phiên bản hCaptcha với Capsolver
Làm thế nào để dễ dàng vượt qua bất kỳ phiên bản hCaptcha nào bằng cách sử dụng Capsolver

Discover how to solve any version of hCaptcha using Capsolver: Detailed guidance on fetch value retrieval, base64 conversion, and JSON configuration

hCaptcha

06-Nov-2023

How to solve hCaptcha with Node.JS
How to solve hCaptcha with Node.JS

In this article, we will show you how to solve hCaptcha with Node.JS.

hCaptcha

27-Sep-2023

How to solve hCaptcha Enterprise with Python
How to solve hCaptcha Enterprise with Python

In this article, we will show you how to solve hCaptcha Enterprise with Python.

hCaptcha

25-Sep-2023