puppeteer-extra-plugin-recaptcha
Advanced tools
Comparing version 3.1.8 to 3.1.9
@@ -26,9 +26,9 @@ import * as types from './types'; | ||
findRecaptchas(): Promise<{ | ||
captchas: (types.CaptchaInfo | undefined)[]; | ||
captchas: types.CaptchaInfo[]; | ||
error: any; | ||
}>; | ||
enterRecaptchaSolutions(): Promise<{ | ||
solved: (types.CaptchaSolved | undefined)[]; | ||
solved: types.CaptchaSolved[]; | ||
error: any; | ||
}>; | ||
} |
@@ -129,2 +129,7 @@ "use strict"; | ||
} | ||
// Not all reCAPTCHAs are in forms | ||
// https://github.com/berstend/puppeteer-extra/issues/57 | ||
if (document && document.body) { | ||
return document.body.querySelector(`[name='g-recaptcha-response']`); | ||
} | ||
} | ||
@@ -131,0 +136,0 @@ getClientById(id) { |
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.5 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.8 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -141,2 +141,7 @@ * @license MIT | ||
} | ||
// Not all reCAPTCHAs are in forms | ||
// https://github.com/berstend/puppeteer-extra/issues/57 | ||
if (document && document.body) { | ||
return document.body.querySelector(`[name='g-recaptcha-response']`); | ||
} | ||
} | ||
@@ -326,5 +331,171 @@ getClientById(id) { | ||
// https://github.com/bochkarev-artem/2captcha/blob/master/index.js | ||
// TODO: Create our own API wrapper | ||
var http = require('http'); | ||
var https = require('https'); | ||
var url = require('url'); | ||
var querystring = require('querystring'); | ||
var apiKey; | ||
var apiInUrl = 'http://2captcha.com/in.php'; | ||
var apiResUrl = 'http://2captcha.com/res.php'; | ||
var apiMethod = 'base64'; | ||
var apiMethodRecaptcha = 'userrecaptcha'; | ||
var SOFT_ID = '2589'; | ||
var defaultOptions = { | ||
pollingInterval: 2000, | ||
retries: 3 | ||
}; | ||
function pollCaptcha(captchaId, options, invalid, callback) { | ||
invalid = invalid.bind({ options: options, captchaId: captchaId }); | ||
var intervalId = setInterval(function () { | ||
var httpRequestOptions = url.parse(apiResUrl + | ||
'?action=get&soft_id=' + | ||
SOFT_ID + | ||
'&key=' + | ||
apiKey + | ||
'&id=' + | ||
captchaId); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
if (body === 'CAPCHA_NOT_READY') { | ||
return; | ||
} | ||
clearInterval(intervalId); | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
callback(result[0]); //error | ||
} | ||
else { | ||
callback(null, { | ||
id: captchaId, | ||
text: result[1] | ||
}, invalid); | ||
} | ||
callback = function () { }; // prevent the callback from being called more than once, if multiple http requests are open at the same time. | ||
}); | ||
}); | ||
request.end(); | ||
}, options.pollingInterval || defaultOptions.pollingInterval); | ||
} | ||
const setApiKey = function (key) { | ||
apiKey = key; | ||
}; | ||
const decode = function (base64, options, callback) { | ||
if (!callback) { | ||
callback = options; | ||
options = defaultOptions; | ||
} | ||
var httpRequestOptions = url.parse(apiInUrl); | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethod, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
body: base64 | ||
}; | ||
postData = querystring.stringify(postData); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
return callback(result[0]); | ||
} | ||
pollCaptcha(result[1], options, function (error) { | ||
var callbackToInitialCallback = callback; | ||
report(this.captchaId); | ||
if (error) { | ||
return callbackToInitialCallback('CAPTCHA_FAILED'); | ||
} | ||
if (!this.options.retries) { | ||
this.options.retries = defaultOptions.retries; | ||
} | ||
if (this.options.retries > 1) { | ||
this.options.retries = this.options.retries - 1; | ||
decode(base64, this.options, callback); | ||
} | ||
else { | ||
callbackToInitialCallback('CAPTCHA_FAILED_TOO_MANY_TIMES'); | ||
} | ||
}, callback); | ||
}); | ||
}); | ||
request.write(postData); | ||
request.end(); | ||
}; | ||
const decodeReCaptcha = function (captcha, pageUrl, options, callback) { | ||
if (!callback) { | ||
callback = options; | ||
options = defaultOptions; | ||
} | ||
var httpRequestOptions = url.parse(apiInUrl); | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethodRecaptcha, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
googlekey: captcha, | ||
pageurl: pageUrl | ||
}; | ||
postData = querystring.stringify(postData); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
return callback(result[0]); | ||
} | ||
pollCaptcha(result[1], options, function (error) { | ||
var callbackToInitialCallback = callback; | ||
report(this.captchaId); | ||
if (error) { | ||
return callbackToInitialCallback('CAPTCHA_FAILED'); | ||
} | ||
if (!this.options.retries) { | ||
this.options.retries = defaultOptions.retries; | ||
} | ||
if (this.options.retries > 1) { | ||
this.options.retries = this.options.retries - 1; | ||
decode(captcha, this.options, callback); | ||
} | ||
else { | ||
callbackToInitialCallback('CAPTCHA_FAILED_TOO_MANY_TIMES'); | ||
} | ||
}, callback); | ||
}); | ||
}); | ||
request.write(postData); | ||
request.end(); | ||
}; | ||
const report = function (captchaId) { | ||
var reportUrl = apiResUrl + | ||
'?action=reportbad&soft_id=' + | ||
SOFT_ID + | ||
'&key=' + | ||
apiKey + | ||
'&id=' + | ||
captchaId; | ||
var options = url.parse(reportUrl); | ||
var request = http.request(options, function (response) { | ||
// var body = '' | ||
// response.on('data', function(chunk) { | ||
// body += chunk | ||
// }) | ||
// response.on('end', function() {}) | ||
}); | ||
request.end(); | ||
}; | ||
const PROVIDER_ID = '2captcha'; | ||
const debug = Debug(`puppeteer-extra-plugin:recaptcha:${PROVIDER_ID}`); | ||
const solver = require('2captcha-api'); | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
@@ -335,4 +506,4 @@ async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { | ||
try { | ||
solver.setApiKey(token); | ||
solver.decodeReCaptcha(sitekey, url, opts, cb); | ||
setApiKey(token); | ||
decodeReCaptcha(sitekey, url, opts, cb); | ||
} | ||
@@ -424,3 +595,3 @@ catch (error) { | ||
// we add some extra waiting logic for developer convenience. | ||
const hasRecaptchaScriptTag = await page.$(`script[src="https://www.google.com/recaptcha/api.js"]`); | ||
const hasRecaptchaScriptTag = await page.$(`script[src^="https://www.google.com/recaptcha/api.js"]`); | ||
this.debug('hasRecaptchaScriptTag', !!hasRecaptchaScriptTag); | ||
@@ -427,0 +598,0 @@ if (hasRecaptchaScriptTag) { |
@@ -16,3 +16,3 @@ import { PuppeteerExtraPlugin } from 'puppeteer-extra-plugin'; | ||
findRecaptchas(page: Page | Frame): Promise<types.FindRecaptchasResult>; | ||
getRecaptchaSolutions(captchas: types.CaptchaInfo[], provider?: types.SolutionProvider): Promise<types.GetSolutionsResult>; | ||
getRecaptchaSolutions(captchas: types.CaptchaInfo[], provider?: types.SolutionProvider): Promise<any>; | ||
enterRecaptchaSolutions(page: Page | Frame, solutions: types.CaptchaSolution[]): Promise<types.EnterRecaptchaSolutionsResult>; | ||
@@ -26,3 +26,3 @@ solveRecaptchas(page: Page | Frame): Promise<types.SolveRecaptchasResult>; | ||
/** Default export, PuppeteerExtraPluginRecaptcha */ | ||
declare const defaultExport: (options?: Partial<types.PluginOptions> | undefined) => PuppeteerExtraPluginRecaptcha; | ||
declare const defaultExport: (options?: Partial<types.PluginOptions>) => PuppeteerExtraPluginRecaptcha; | ||
export default defaultExport; |
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.5 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.8 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -135,2 +135,7 @@ * @license MIT | ||
} | ||
// Not all reCAPTCHAs are in forms | ||
// https://github.com/berstend/puppeteer-extra/issues/57 | ||
if (document && document.body) { | ||
return document.body.querySelector(`[name='g-recaptcha-response']`); | ||
} | ||
} | ||
@@ -320,5 +325,171 @@ getClientById(id) { | ||
// https://github.com/bochkarev-artem/2captcha/blob/master/index.js | ||
// TODO: Create our own API wrapper | ||
var http = require('http'); | ||
var https = require('https'); | ||
var url = require('url'); | ||
var querystring = require('querystring'); | ||
var apiKey; | ||
var apiInUrl = 'http://2captcha.com/in.php'; | ||
var apiResUrl = 'http://2captcha.com/res.php'; | ||
var apiMethod = 'base64'; | ||
var apiMethodRecaptcha = 'userrecaptcha'; | ||
var SOFT_ID = '2589'; | ||
var defaultOptions = { | ||
pollingInterval: 2000, | ||
retries: 3 | ||
}; | ||
function pollCaptcha(captchaId, options, invalid, callback) { | ||
invalid = invalid.bind({ options: options, captchaId: captchaId }); | ||
var intervalId = setInterval(function () { | ||
var httpRequestOptions = url.parse(apiResUrl + | ||
'?action=get&soft_id=' + | ||
SOFT_ID + | ||
'&key=' + | ||
apiKey + | ||
'&id=' + | ||
captchaId); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
if (body === 'CAPCHA_NOT_READY') { | ||
return; | ||
} | ||
clearInterval(intervalId); | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
callback(result[0]); //error | ||
} | ||
else { | ||
callback(null, { | ||
id: captchaId, | ||
text: result[1] | ||
}, invalid); | ||
} | ||
callback = function () { }; // prevent the callback from being called more than once, if multiple http requests are open at the same time. | ||
}); | ||
}); | ||
request.end(); | ||
}, options.pollingInterval || defaultOptions.pollingInterval); | ||
} | ||
const setApiKey = function (key) { | ||
apiKey = key; | ||
}; | ||
const decode = function (base64, options, callback) { | ||
if (!callback) { | ||
callback = options; | ||
options = defaultOptions; | ||
} | ||
var httpRequestOptions = url.parse(apiInUrl); | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethod, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
body: base64 | ||
}; | ||
postData = querystring.stringify(postData); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
return callback(result[0]); | ||
} | ||
pollCaptcha(result[1], options, function (error) { | ||
var callbackToInitialCallback = callback; | ||
report(this.captchaId); | ||
if (error) { | ||
return callbackToInitialCallback('CAPTCHA_FAILED'); | ||
} | ||
if (!this.options.retries) { | ||
this.options.retries = defaultOptions.retries; | ||
} | ||
if (this.options.retries > 1) { | ||
this.options.retries = this.options.retries - 1; | ||
decode(base64, this.options, callback); | ||
} | ||
else { | ||
callbackToInitialCallback('CAPTCHA_FAILED_TOO_MANY_TIMES'); | ||
} | ||
}, callback); | ||
}); | ||
}); | ||
request.write(postData); | ||
request.end(); | ||
}; | ||
const decodeReCaptcha = function (captcha, pageUrl, options, callback) { | ||
if (!callback) { | ||
callback = options; | ||
options = defaultOptions; | ||
} | ||
var httpRequestOptions = url.parse(apiInUrl); | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethodRecaptcha, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
googlekey: captcha, | ||
pageurl: pageUrl | ||
}; | ||
postData = querystring.stringify(postData); | ||
var request = http.request(httpRequestOptions, function (response) { | ||
var body = ''; | ||
response.on('data', function (chunk) { | ||
body += chunk; | ||
}); | ||
response.on('end', function () { | ||
var result = body.split('|'); | ||
if (result[0] !== 'OK') { | ||
return callback(result[0]); | ||
} | ||
pollCaptcha(result[1], options, function (error) { | ||
var callbackToInitialCallback = callback; | ||
report(this.captchaId); | ||
if (error) { | ||
return callbackToInitialCallback('CAPTCHA_FAILED'); | ||
} | ||
if (!this.options.retries) { | ||
this.options.retries = defaultOptions.retries; | ||
} | ||
if (this.options.retries > 1) { | ||
this.options.retries = this.options.retries - 1; | ||
decode(captcha, this.options, callback); | ||
} | ||
else { | ||
callbackToInitialCallback('CAPTCHA_FAILED_TOO_MANY_TIMES'); | ||
} | ||
}, callback); | ||
}); | ||
}); | ||
request.write(postData); | ||
request.end(); | ||
}; | ||
const report = function (captchaId) { | ||
var reportUrl = apiResUrl + | ||
'?action=reportbad&soft_id=' + | ||
SOFT_ID + | ||
'&key=' + | ||
apiKey + | ||
'&id=' + | ||
captchaId; | ||
var options = url.parse(reportUrl); | ||
var request = http.request(options, function (response) { | ||
// var body = '' | ||
// response.on('data', function(chunk) { | ||
// body += chunk | ||
// }) | ||
// response.on('end', function() {}) | ||
}); | ||
request.end(); | ||
}; | ||
const PROVIDER_ID = '2captcha'; | ||
const debug = Debug(`puppeteer-extra-plugin:recaptcha:${PROVIDER_ID}`); | ||
const solver = require('2captcha-api'); | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
@@ -329,4 +500,4 @@ async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { | ||
try { | ||
solver.setApiKey(token); | ||
solver.decodeReCaptcha(sitekey, url, opts, cb); | ||
setApiKey(token); | ||
decodeReCaptcha(sitekey, url, opts, cb); | ||
} | ||
@@ -418,3 +589,3 @@ catch (error) { | ||
// we add some extra waiting logic for developer convenience. | ||
const hasRecaptchaScriptTag = await page.$(`script[src="https://www.google.com/recaptcha/api.js"]`); | ||
const hasRecaptchaScriptTag = await page.$(`script[src^="https://www.google.com/recaptcha/api.js"]`); | ||
this.debug('hasRecaptchaScriptTag', !!hasRecaptchaScriptTag); | ||
@@ -421,0 +592,0 @@ if (hasRecaptchaScriptTag) { |
@@ -58,3 +58,3 @@ "use strict"; | ||
// we add some extra waiting logic for developer convenience. | ||
const hasRecaptchaScriptTag = await page.$(`script[src="https://www.google.com/recaptcha/api.js"]`); | ||
const hasRecaptchaScriptTag = await page.$(`script[src^="https://www.google.com/recaptcha/api.js"]`); | ||
this.debug('hasRecaptchaScriptTag', !!hasRecaptchaScriptTag); | ||
@@ -61,0 +61,0 @@ if (hasRecaptchaScriptTag) { |
@@ -5,2 +5,9 @@ "use strict"; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -10,3 +17,4 @@ exports.PROVIDER_ID = '2captcha'; | ||
const debug = debug_1.default(`puppeteer-extra-plugin:recaptcha:${exports.PROVIDER_ID}`); | ||
const solver = require('2captcha-api'); | ||
// const solver = require('./2captcha-api') | ||
const solver = __importStar(require("./2captcha-api")); | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
@@ -13,0 +21,0 @@ async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { |
{ | ||
"name": "puppeteer-extra-plugin-recaptcha", | ||
"version": "3.1.8", | ||
"version": "3.1.9", | ||
"description": "A puppeteer-extra plugin to solve reCAPTCHAs automatically.", | ||
@@ -22,3 +22,3 @@ "main": "dist/index.cjs.js", | ||
"test": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ava -v src/**.test.ts", | ||
"test-ci": "yarn build && TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ava -v dist/*.test.js", | ||
"test-ci": "yarn build && TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' ava --fail-fast -v dist/*.test.js", | ||
"ambient-dts": "yarn ambient-dts-copy && yarn ambient-dts-fix-path", | ||
@@ -55,3 +55,3 @@ "ambient-dts-copy": "copyfiles -u 1 \"src/**/*.d.ts\" dist", | ||
"@types/debug": "^4.1.5", | ||
"@types/node": "^12.12.14", | ||
"@types/node": "^13.1.4", | ||
"@types/puppeteer": "^2.0.0", | ||
@@ -61,3 +61,3 @@ "ava": "2.4.0", | ||
"puppeteer": "^2.0.0", | ||
"puppeteer-extra": "^3.1.7", | ||
"puppeteer-extra": "^3.1.8", | ||
"replace-in-files-cli": "^0.3.0", | ||
@@ -68,9 +68,8 @@ "ts-node": "^8.5.4", | ||
"tslint-config-standard": "^9.0.0", | ||
"typescript": "^3.7.2" | ||
"typescript": "^3.7.4" | ||
}, | ||
"dependencies": { | ||
"2captcha-api": "^1.0.0", | ||
"debug": "^4.1.1", | ||
"merge-deep": "^3.0.2", | ||
"puppeteer-extra-plugin": "^3.1.2" | ||
"puppeteer-extra-plugin": "^3.1.3" | ||
}, | ||
@@ -80,3 +79,3 @@ "peerDependencies": { | ||
}, | ||
"gitHead": "6d452681fe832a6d864616ee8fa79134ebd19be7" | ||
"gitHead": "6a89e1196bdf8327ee9a2ba8b18f861d9fc209d3" | ||
} |
@@ -26,2 +26,7 @@ # puppeteer-extra-plugin-recaptcha [![Build Status](https://travis-ci.org/berstend/puppeteer-extra.svg?branch=master)](https://travis-ci.org/berstend/puppeteer-extra) [![npm](https://img.shields.io/npm/v/puppeteer-extra-plugin-recaptcha.svg)](https://www.npmjs.com/package/puppeteer-extra-plugin-recaptcha) | ||
##### `3.1.9` | ||
- Support reCAPTCHAs not in forms ([#57](https://github.com/berstend/puppeteer-extra/issues/57)) | ||
- Make script detection more fuzzy ([#48](https://github.com/berstend/puppeteer-extra/issues/48)) | ||
##### `3.1.6` | ||
@@ -28,0 +33,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
226755
4
27
2430
245
8
- Removed2captcha-api@^1.0.0
- Removed2captcha-api@1.0.0(transitive)