This project is a simple example that demonstrates how to use Playwright in combination with the 2captcha-ts library to automatically solve hCaptcha challenges on a demo webpage.
- Browser Automation: Launch Chromium using Playwright in non-headless mode for visual debugging.
- Captcha Solving: Utilize the 2captcha service to solve hCaptcha challenges.
- Form Submission: Automatically insert the captcha solution into form fields and submit the form.
- Result Verification: Wait for a specific confirmation message on the page to ensure that the form was processed correctly.
- Node.js (version 14 or higher is recommended)
- npm
- A valid 2captcha API Key
Update theAPI_KEY
constant in the script with your key.
-
Clone the repository (if applicable):
git clone https://github.com/clemmie24m/hcaptcha-playwright.git cd hcaptcha-playwright
-
Install dependencies:
npm install
or manualy:
npm install playwright 2captcha-ts
- API Key: Replace
"2captcha_api_key"
with your actual 2captcha API key in the script. - Site Key: The
SITEKEY
constant is set to the hCaptcha site key required by the demo page. - Page URL: The
PAGE_URL
variable points to the demo page that contains an hCaptcha form. - Headless Mode: Set the
HEADLESS
constant totrue
if you prefer running the browser in headless mode.
Run the script using Node.js:
node index.js
The script will:
- Launch a Chromium browser.
- Open the demo page.
- Wait for the captcha form to load.
- Send the captcha challenge to 2captcha for solving.
- Inject the solution into the form fields.
- Submit the form and wait for a confirmation message to appear.
If successful, you will see a message in the console indicating that the captcha has been completed successfully.
The main steps performed by the script include:
- Launching the Browser:
Using Playwright's
chromium.launch()
with a custom viewport size to mimic a real device. - Navigating to the Target Page: Opening the demo page URL and waiting for the captcha form to become visible.
- Captcha Solving: Sending the challenge details (page URL and site key) to 2captcha via the 2captcha-ts library and retrieving the solution.
- Injecting the Captcha Response: Using page.evaluate() to populate the necessary textareas with the solved captcha token.
- Form Submission and Verification:
Clicking the submit button and waiting for a specific
<h2>
element containing the confirmation message.
This project is provided for educational purposes. Feel free to modify and use it in your own projects.