Blog
How to solve hCaptcha using Puppeteer and Capsolver Extension

How to solve hCaptcha using Puppeteer and Capsolver Extension

Logo of Capsolver

CapSolver Blogger

How to use capsolver

23-Jul-2023

How to solve hCaptcha using Puppeteer and Capsolver Extension

1. Installing puppeteer components

⚠️In this blog, will explain how to setup puppeteer js with capsolver extension for solve hcaptcha. But you can apply this for all the captchas.

npm i puppeteer puppeteer-extra puppeteer-extra-plugin-stealth

2. Setting up the extension

Download the archive with the extension, and unzip it to the folder ./CapSolver.Browser.Extension in the root of the project.

The extension has many settings, including automatic solution of the specified type of captcha, support for proxy, and other settings. The settings are available in the file ./assets/config.json.

These settings are:

{
    "apiKey": "YourApiKey",
  "useCapsolver": true, Ex: true / false

  "useProxy": false, Ex: true / false
  "proxyType": "http", Ex: http / socks5 / socks4
  "hostOrIp": "", Ex: @google.com or 154.3.2.3
  "port": "", Ex: 8983
  "proxyLogin": "", Optional. Ex: dkkwje
  "proxyPassword": "", Optional. Ex: dkwjek

  "enabledForBlacklistControl": false, Ex: true / false
  "blackUrlList": [], Ex: ["https://youtube.com","https://capsolver.com"] or [""https://capsolver.com"]

  "enabledForRecaptcha": true, Ex: true / false
  "enabledForRecaptchaV3": true, Ex: true / false
  "enabledForHCaptcha": true, Ex: true / false
  "enabledForFunCaptcha": true, Ex: true / false

  "reCaptchaMode": "click", Ex: click / token
  "hCaptchaMode": "token",  Ex: click / token

  "reCaptchaDelayTime": 0,
  "hCaptchaDelayTime": 0,

  "reCaptchaRepeatTimes": 10,
  "reCaptcha3RepeatTimes": 10,
  "hCaptchaRepeatTimes": 10,
  "funCaptchaRepeatTimes": 10
}

Enter your API key in the extension settings file ./assets/config.json. Your key must be written to the value of the apiKey field. You can see and copy you're API key on the page.

Example: apiKey: "CAP-4FDBD3SDFSD-23S-2-3"

In this example, we will use hCaptchaMode token, but we can use click, for hCaptcha it's recommended to use token mode.

3. Setting up Puppeter for solve hCaptcha with Capsolver Extension

const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const { executablePath } = require('puppeteer'); 

(async () => {
  const pathToExtension = require('path').join(__dirname, 'CapSolver.Browser.Extension');
  puppeteer.use(StealthPlugin())
  const browser = await puppeteer.launch({
    headless: false,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
    ],
    executablePath: executablePath()
  });
  
  const [page] = await browser.pages()
})();

Next, is opening the page https://accounts.hcaptcha.com/demo, and sending the captcha to capsolver.

Using page.goto() we go to the page https://accounts.hcaptcha.com/demo. Next, you need to send a captcha for a solution, this can be done manually or automatically.

In our example, we will send a captcha manually, for this we wait until the extension button with the CSS selector ##checkbox is available, then click on this button. After clicking on the button, the captcha will go to the service for a solution.

await page.goto('siteURL') 

// Waiting for the element with the CSS selector "#checkbox" to be available
await page.waitForSelector('#checkbox')
// Click on the element with the specified selector
await page.click('#checkbox')

Full Code:

const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
const { executablePath } = require('puppeteer'); 

(async () => {
  const pathToExtension = require('path').join(__dirname, 'CapSolver.Browser.Extension');
  puppeteer.use(StealthPlugin())
  const browser = await puppeteer.launch({
    headless: false,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
    ],
    executablePath: executablePath()
  });
  
  const [page] = await browser.pages()
  // Opening a page
await page.goto('siteURL') 

// Waiting for the element with the CSS selector "#checkbox" to be available
await page.waitForSelector('#checkbox')
// Click on the element with the specified selector
await page.click('#checkbox')
})();

And that is! You solved hCaptcha using Capsolver Extension and Puppeteer. If you need to solve other captchas, you just need to replicate the tutorial for the other captchas.

Capsolver Team 💜

More

How to solve AWS Captcha using Puppeteer [Javascript] with Capsolver Extension
How to solve AWS Captcha using Puppeteer [Javascript] with Capsolver Extension

Learn to seamlessly solve AWS Captcha with Puppeteer and Capsolver Extension, a detailed guide on setting up and automating captcha solutions effectively

Extension

29-Nov-2023

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

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

Extension

24-Nov-2023

How to solve reCaptcha v2 using Selenium [Javascript] with Capsolver Extension
How to solve reCaptcha v2 using Selenium [Javascript] with Capsolver Extension

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

Extension

22-Nov-2023

How to identify any captcha (reCaptcha/hCaptcha/funCaptcha) and their parameters
How to identify any captcha (reCAPTCHA/hCaptcha/FunCaptcha) and their parameters

Master CAPTCHA detection with Capsolver: This guide covers identifying parameters for reCaptcha, hCaptcha, and FunCaptcha, making it simpler to solve them effectively.

Extension

31-Oct-2023

Capsolver's Captcha Solver Chrome Extension
Capsolver's Captcha Solver Chrome Extension

Websites use captcha challenges to distinguish real human users from bots and automated scripts. While important for security, captchas can be frustrating speed bumps during automation tasks. To smooth over captchas, Capsolver offers an ingenious Chrome extension for automated solving. In this post, we’ll explore Capsolver’s extension, how to install and use it, supported captcha types, and more.

Extension

23-Oct-2023

Capsolver Extension - Solve Image Captcha in your browser
Capsolver Extension - Solve Image Captcha in your browser

Solve image captcha in any webpage without effort using Capsolver Captcha Solver Extension

Extension

30-Aug-2023