UNPKG

auto-captcha-solver

Version:

Automatically detect and solve various captcha types in Playwright & Puppeteer with 2Captcha/CapMonster Cloud integration

38 lines 1.51 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createCapMonsterTask = createCapMonsterTask; exports.getCapMonsterTaskResult = getCapMonsterTaskResult; const axios_1 = __importDefault(require("axios")); // CapMonster API URL const CAPMONSTER_API_URL = 'https://api.capmonster.cloud'; // Function to create a task using CapMonster async function createCapMonsterTask(apiKey, taskData) { const response = await axios_1.default.post(`${CAPMONSTER_API_URL}/createTask`, { clientKey: apiKey, task: taskData }); if (response.data.errorId) { throw new Error(`CapMonster API Error: ${response.data.errorCode}`); } return response.data.taskId; } // Function to get task results from CapMonster async function getCapMonsterTaskResult(apiKey, taskId) { while (true) { const response = await axios_1.default.post(`${CAPMONSTER_API_URL}/getTaskResult`, { clientKey: apiKey, taskId }); if (response.data.errorId) { throw new Error(`CapMonster API Error: ${response.data.errorCode}`); } if (response.data.status === 'ready') { return response.data.solution; } await new Promise((resolve) => setTimeout(resolve, 2000)); // Wait before retrying } } //# sourceMappingURL=capmonster-api.js.map