puppeteer-extra-plugin-recaptcha
Advanced tools
Comparing version 3.1.19 to 3.2.0
@@ -5,6 +5,6 @@ "use strict"; | ||
exports.ContentScriptDefaultOpts = { | ||
visualFeedback: true | ||
visualFeedback: true, | ||
}; | ||
exports.ContentScriptDefaultData = { | ||
solutions: [] | ||
solutions: [], | ||
}; | ||
@@ -20,3 +20,6 @@ /** | ||
// make sure the element is visible - this is equivalent to jquery's is(':visible') | ||
this._isVisible = (elem) => !!(elem.offsetWidth || elem.offsetHeight || (typeof elem.getClientRects === 'function' && elem.getClientRects().length)); | ||
this._isVisible = (elem) => !!(elem.offsetWidth || | ||
elem.offsetHeight || | ||
(typeof elem.getClientRects === 'function' && | ||
elem.getClientRects().length)); | ||
this.opts = opts; | ||
@@ -33,7 +36,7 @@ this.data = data; | ||
item = Object.keys(newObj).length ? newObj : item; | ||
Object.keys(item).forEach(key => { | ||
Object.keys(item).forEach((key) => { | ||
if (ignoreHTML && isHTML(item[key])) | ||
return; | ||
if (isObject(item[key])) { | ||
Object.keys(item[key]).forEach(innerKey => { | ||
Object.keys(item[key]).forEach((innerKey) => { | ||
if (ignoreHTML && isHTML(item[key][innerKey])) | ||
@@ -56,3 +59,3 @@ return; | ||
_getKeyByValue(object, value) { | ||
return Object.keys(object).find(key => object[key] === value); | ||
return Object.keys(object).find((key) => object[key] === value); | ||
} | ||
@@ -101,8 +104,6 @@ async _waitUntilDocumentReady() { | ||
_findVisibleIframeNodeById(id) { | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || | ||
''}"]`); | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || ''}"]`); | ||
} | ||
_hideChallengeWindowIfPresent(id) { | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || | ||
''}"]`); | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || ''}"]`); | ||
if (!frame) { | ||
@@ -134,9 +135,9 @@ return; | ||
return this._findVisibleIframeNodes() | ||
.filter($f => this._isVisible($f)) | ||
.map($f => this._paintCaptchaBusy($f)) | ||
.filter($f => $f && $f.getAttribute('name')) | ||
.map($f => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map(rawId => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
.filter(($f) => this._isVisible($f)) | ||
.map(($f) => this._paintCaptchaBusy($f)) | ||
.filter(($f) => $f && $f.getAttribute('name')) | ||
.map(($f) => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map((rawId) => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
) | ||
.filter(id => id); | ||
.filter((id) => id); | ||
} | ||
@@ -165,3 +166,3 @@ getResponseInputById(id) { | ||
let client = Object.values(clients || {}) | ||
.filter(obj => this._getKeyByValue(obj, id)) | ||
.filter((obj) => this._getKeyByValue(obj, id)) | ||
.shift(); // returns first entry in array or undefined | ||
@@ -182,2 +183,3 @@ if (!client) | ||
info.id = client.id; | ||
info.s = client.s; // google site specific | ||
info.widgetId = client.widgetId; | ||
@@ -190,3 +192,3 @@ info.display = this._pick([ | ||
'height', | ||
'theme' | ||
'theme', | ||
])(client); | ||
@@ -204,3 +206,3 @@ // callbacks can be strings or funtion refs | ||
captchas: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -213,5 +215,5 @@ try { | ||
result.captchas = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => this.extractInfoFromClient(client)) | ||
.map(info => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => this.extractInfoFromClient(client)) | ||
.map((info) => { | ||
if (!info) | ||
@@ -223,3 +225,3 @@ return; | ||
}) | ||
.filter(info => info); | ||
.filter((info) => info); | ||
} | ||
@@ -235,3 +237,3 @@ catch (error) { | ||
solved: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -251,8 +253,8 @@ try { | ||
result.solved = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => { | ||
const solved = { | ||
id: client.id, | ||
responseElement: false, | ||
responseCallback: false | ||
responseCallback: false, | ||
}; | ||
@@ -264,3 +266,3 @@ const $iframe = this._findVisibleIframeNodeById(solved.id); | ||
} | ||
const solution = solutions.find(s => s.id === solved.id); | ||
const solution = solutions.find((s) => s.id === solved.id); | ||
if (!solution || !solution.text) { | ||
@@ -267,0 +269,0 @@ solved.error = `Solution not found for id '${solved.id}'`; |
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.18 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.19 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -16,6 +16,6 @@ * @license MIT | ||
const ContentScriptDefaultOpts = { | ||
visualFeedback: true | ||
visualFeedback: true, | ||
}; | ||
const ContentScriptDefaultData = { | ||
solutions: [] | ||
solutions: [], | ||
}; | ||
@@ -31,3 +31,6 @@ /** | ||
// make sure the element is visible - this is equivalent to jquery's is(':visible') | ||
this._isVisible = (elem) => !!(elem.offsetWidth || elem.offsetHeight || (typeof elem.getClientRects === 'function' && elem.getClientRects().length)); | ||
this._isVisible = (elem) => !!(elem.offsetWidth || | ||
elem.offsetHeight || | ||
(typeof elem.getClientRects === 'function' && | ||
elem.getClientRects().length)); | ||
this.opts = opts; | ||
@@ -44,7 +47,7 @@ this.data = data; | ||
item = Object.keys(newObj).length ? newObj : item; | ||
Object.keys(item).forEach(key => { | ||
Object.keys(item).forEach((key) => { | ||
if (ignoreHTML && isHTML(item[key])) | ||
return; | ||
if (isObject(item[key])) { | ||
Object.keys(item[key]).forEach(innerKey => { | ||
Object.keys(item[key]).forEach((innerKey) => { | ||
if (ignoreHTML && isHTML(item[key][innerKey])) | ||
@@ -67,3 +70,3 @@ return; | ||
_getKeyByValue(object, value) { | ||
return Object.keys(object).find(key => object[key] === value); | ||
return Object.keys(object).find((key) => object[key] === value); | ||
} | ||
@@ -112,8 +115,6 @@ async _waitUntilDocumentReady() { | ||
_findVisibleIframeNodeById(id) { | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || | ||
''}"]`); | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || ''}"]`); | ||
} | ||
_hideChallengeWindowIfPresent(id) { | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || | ||
''}"]`); | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || ''}"]`); | ||
if (!frame) { | ||
@@ -145,9 +146,9 @@ return; | ||
return this._findVisibleIframeNodes() | ||
.filter($f => this._isVisible($f)) | ||
.map($f => this._paintCaptchaBusy($f)) | ||
.filter($f => $f && $f.getAttribute('name')) | ||
.map($f => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map(rawId => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
.filter(($f) => this._isVisible($f)) | ||
.map(($f) => this._paintCaptchaBusy($f)) | ||
.filter(($f) => $f && $f.getAttribute('name')) | ||
.map(($f) => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map((rawId) => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
) | ||
.filter(id => id); | ||
.filter((id) => id); | ||
} | ||
@@ -176,3 +177,3 @@ getResponseInputById(id) { | ||
let client = Object.values(clients || {}) | ||
.filter(obj => this._getKeyByValue(obj, id)) | ||
.filter((obj) => this._getKeyByValue(obj, id)) | ||
.shift(); // returns first entry in array or undefined | ||
@@ -193,2 +194,3 @@ if (!client) | ||
info.id = client.id; | ||
info.s = client.s; // google site specific | ||
info.widgetId = client.widgetId; | ||
@@ -201,3 +203,3 @@ info.display = this._pick([ | ||
'height', | ||
'theme' | ||
'theme', | ||
])(client); | ||
@@ -215,3 +217,3 @@ // callbacks can be strings or funtion refs | ||
captchas: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -224,5 +226,5 @@ try { | ||
result.captchas = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => this.extractInfoFromClient(client)) | ||
.map(info => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => this.extractInfoFromClient(client)) | ||
.map((info) => { | ||
if (!info) | ||
@@ -234,3 +236,3 @@ return; | ||
}) | ||
.filter(info => info); | ||
.filter((info) => info); | ||
} | ||
@@ -246,3 +248,3 @@ catch (error) { | ||
solved: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -262,8 +264,8 @@ try { | ||
result.solved = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => { | ||
const solved = { | ||
id: client.id, | ||
responseElement: false, | ||
responseCallback: false | ||
responseCallback: false, | ||
}; | ||
@@ -275,3 +277,3 @@ const $iframe = this._findVisibleIframeNodeById(solved.id); | ||
} | ||
const solution = solutions.find(s => s.id === solved.id); | ||
const solution = solutions.find((s) => s.id === solved.id); | ||
if (!solution || !solution.text) { | ||
@@ -378,3 +380,3 @@ solved.error = `Solution not found for id '${solved.id}'`; | ||
pollingInterval: 2000, | ||
retries: 3 | ||
retries: 3, | ||
}; | ||
@@ -408,3 +410,3 @@ function pollCaptcha(captchaId, options, invalid, callback) { | ||
id: captchaId, | ||
text: result[1] | ||
text: result[1], | ||
}, invalid); | ||
@@ -432,3 +434,3 @@ } | ||
soft_id: SOFT_ID, | ||
body: base64 | ||
body: base64, | ||
}; | ||
@@ -468,3 +470,3 @@ postData = querystring.stringify(postData); | ||
}; | ||
const decodeReCaptcha = function (captcha, pageUrl, options, callback) { | ||
const decodeReCaptcha = function (captcha, pageUrl, extraData, options, callback) { | ||
if (!callback) { | ||
@@ -476,9 +478,3 @@ callback = options; | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethodRecaptcha, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
googlekey: captcha, | ||
pageurl: pageUrl | ||
}; | ||
var postData = Object.assign({ method: apiMethodRecaptcha, key: apiKey, soft_id: SOFT_ID, googlekey: captcha, pageurl: pageUrl }, extraData); | ||
postData = querystring.stringify(postData); | ||
@@ -539,8 +535,8 @@ var request = http.request(httpRequestOptions, function (response) { | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { | ||
return new Promise(resolve => { | ||
async function decodeRecaptchaAsync(token, sitekey, url, extraData, opts = { pollingInterval: 2000 }) { | ||
return new Promise((resolve) => { | ||
const cb = (err, result, invalid) => resolve({ err, result, invalid }); | ||
try { | ||
setApiKey(token); | ||
decodeReCaptcha(sitekey, url, opts, cb); | ||
decodeReCaptcha(sitekey, url, extraData, opts, cb); | ||
} | ||
@@ -553,8 +549,8 @@ catch (error) { | ||
async function getSolutions(captchas = [], token) { | ||
const solutions = await Promise.all(captchas.map(c => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find(s => !!s.error) }; | ||
const solutions = await Promise.all(captchas.map((c) => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find((s) => !!s.error) }; | ||
} | ||
async function getSolution(captcha, token) { | ||
const solution = { | ||
provider: PROVIDER_ID | ||
provider: PROVIDER_ID, | ||
}; | ||
@@ -568,3 +564,7 @@ try { | ||
debug('Requesting solution..', solution); | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url); | ||
const extraData = {}; | ||
if (captcha.s) { | ||
extraData['data-s'] = captcha.s; // google site specific property | ||
} | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url, extraData); | ||
debug('Got response', { err, result, invalid }); | ||
@@ -571,0 +571,0 @@ if (err) |
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.18 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.19 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -10,6 +10,6 @@ * @license MIT | ||
const ContentScriptDefaultOpts = { | ||
visualFeedback: true | ||
visualFeedback: true, | ||
}; | ||
const ContentScriptDefaultData = { | ||
solutions: [] | ||
solutions: [], | ||
}; | ||
@@ -25,3 +25,6 @@ /** | ||
// make sure the element is visible - this is equivalent to jquery's is(':visible') | ||
this._isVisible = (elem) => !!(elem.offsetWidth || elem.offsetHeight || (typeof elem.getClientRects === 'function' && elem.getClientRects().length)); | ||
this._isVisible = (elem) => !!(elem.offsetWidth || | ||
elem.offsetHeight || | ||
(typeof elem.getClientRects === 'function' && | ||
elem.getClientRects().length)); | ||
this.opts = opts; | ||
@@ -38,7 +41,7 @@ this.data = data; | ||
item = Object.keys(newObj).length ? newObj : item; | ||
Object.keys(item).forEach(key => { | ||
Object.keys(item).forEach((key) => { | ||
if (ignoreHTML && isHTML(item[key])) | ||
return; | ||
if (isObject(item[key])) { | ||
Object.keys(item[key]).forEach(innerKey => { | ||
Object.keys(item[key]).forEach((innerKey) => { | ||
if (ignoreHTML && isHTML(item[key][innerKey])) | ||
@@ -61,3 +64,3 @@ return; | ||
_getKeyByValue(object, value) { | ||
return Object.keys(object).find(key => object[key] === value); | ||
return Object.keys(object).find((key) => object[key] === value); | ||
} | ||
@@ -106,8 +109,6 @@ async _waitUntilDocumentReady() { | ||
_findVisibleIframeNodeById(id) { | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || | ||
''}"]`); | ||
return document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/anchor'][name^="a-${id || ''}"]`); | ||
} | ||
_hideChallengeWindowIfPresent(id) { | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || | ||
''}"]`); | ||
let frame = document.querySelector(`iframe[src^='https://www.google.com/recaptcha/api2/bframe'][name^="c-${id || ''}"]`); | ||
if (!frame) { | ||
@@ -139,9 +140,9 @@ return; | ||
return this._findVisibleIframeNodes() | ||
.filter($f => this._isVisible($f)) | ||
.map($f => this._paintCaptchaBusy($f)) | ||
.filter($f => $f && $f.getAttribute('name')) | ||
.map($f => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map(rawId => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
.filter(($f) => this._isVisible($f)) | ||
.map(($f) => this._paintCaptchaBusy($f)) | ||
.filter(($f) => $f && $f.getAttribute('name')) | ||
.map(($f) => $f.getAttribute('name') || '') // a-841543e13666 | ||
.map((rawId) => rawId.split('-').slice(-1)[0] // a-841543e13666 => 841543e13666 | ||
) | ||
.filter(id => id); | ||
.filter((id) => id); | ||
} | ||
@@ -170,3 +171,3 @@ getResponseInputById(id) { | ||
let client = Object.values(clients || {}) | ||
.filter(obj => this._getKeyByValue(obj, id)) | ||
.filter((obj) => this._getKeyByValue(obj, id)) | ||
.shift(); // returns first entry in array or undefined | ||
@@ -187,2 +188,3 @@ if (!client) | ||
info.id = client.id; | ||
info.s = client.s; // google site specific | ||
info.widgetId = client.widgetId; | ||
@@ -195,3 +197,3 @@ info.display = this._pick([ | ||
'height', | ||
'theme' | ||
'theme', | ||
])(client); | ||
@@ -209,3 +211,3 @@ // callbacks can be strings or funtion refs | ||
captchas: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -218,5 +220,5 @@ try { | ||
result.captchas = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => this.extractInfoFromClient(client)) | ||
.map(info => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => this.extractInfoFromClient(client)) | ||
.map((info) => { | ||
if (!info) | ||
@@ -228,3 +230,3 @@ return; | ||
}) | ||
.filter(info => info); | ||
.filter((info) => info); | ||
} | ||
@@ -240,3 +242,3 @@ catch (error) { | ||
solved: [], | ||
error: null | ||
error: null, | ||
}; | ||
@@ -256,8 +258,8 @@ try { | ||
result.solved = this.getVisibleIframesIds() | ||
.map(id => this.getClientById(id)) | ||
.map(client => { | ||
.map((id) => this.getClientById(id)) | ||
.map((client) => { | ||
const solved = { | ||
id: client.id, | ||
responseElement: false, | ||
responseCallback: false | ||
responseCallback: false, | ||
}; | ||
@@ -269,3 +271,3 @@ const $iframe = this._findVisibleIframeNodeById(solved.id); | ||
} | ||
const solution = solutions.find(s => s.id === solved.id); | ||
const solution = solutions.find((s) => s.id === solved.id); | ||
if (!solution || !solution.text) { | ||
@@ -372,3 +374,3 @@ solved.error = `Solution not found for id '${solved.id}'`; | ||
pollingInterval: 2000, | ||
retries: 3 | ||
retries: 3, | ||
}; | ||
@@ -402,3 +404,3 @@ function pollCaptcha(captchaId, options, invalid, callback) { | ||
id: captchaId, | ||
text: result[1] | ||
text: result[1], | ||
}, invalid); | ||
@@ -426,3 +428,3 @@ } | ||
soft_id: SOFT_ID, | ||
body: base64 | ||
body: base64, | ||
}; | ||
@@ -462,3 +464,3 @@ postData = querystring.stringify(postData); | ||
}; | ||
const decodeReCaptcha = function (captcha, pageUrl, options, callback) { | ||
const decodeReCaptcha = function (captcha, pageUrl, extraData, options, callback) { | ||
if (!callback) { | ||
@@ -470,9 +472,3 @@ callback = options; | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethodRecaptcha, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
googlekey: captcha, | ||
pageurl: pageUrl | ||
}; | ||
var postData = Object.assign({ method: apiMethodRecaptcha, key: apiKey, soft_id: SOFT_ID, googlekey: captcha, pageurl: pageUrl }, extraData); | ||
postData = querystring.stringify(postData); | ||
@@ -533,8 +529,8 @@ var request = http.request(httpRequestOptions, function (response) { | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { | ||
return new Promise(resolve => { | ||
async function decodeRecaptchaAsync(token, sitekey, url, extraData, opts = { pollingInterval: 2000 }) { | ||
return new Promise((resolve) => { | ||
const cb = (err, result, invalid) => resolve({ err, result, invalid }); | ||
try { | ||
setApiKey(token); | ||
decodeReCaptcha(sitekey, url, opts, cb); | ||
decodeReCaptcha(sitekey, url, extraData, opts, cb); | ||
} | ||
@@ -547,8 +543,8 @@ catch (error) { | ||
async function getSolutions(captchas = [], token) { | ||
const solutions = await Promise.all(captchas.map(c => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find(s => !!s.error) }; | ||
const solutions = await Promise.all(captchas.map((c) => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find((s) => !!s.error) }; | ||
} | ||
async function getSolution(captcha, token) { | ||
const solution = { | ||
provider: PROVIDER_ID | ||
provider: PROVIDER_ID, | ||
}; | ||
@@ -562,3 +558,7 @@ try { | ||
debug('Requesting solution..', solution); | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url); | ||
const extraData = {}; | ||
if (captcha.s) { | ||
extraData['data-s'] = captcha.s; // google site specific property | ||
} | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url, extraData); | ||
debug('Got response', { err, result, invalid }); | ||
@@ -565,0 +565,0 @@ if (err) |
export declare const setApiKey: (key: any) => void; | ||
export declare const decode: (base64: any, options: any, callback: any) => void; | ||
export declare const decodeReCaptcha: (captcha: any, pageUrl: any, options: any, callback: any) => void; | ||
export declare const decodeReCaptcha: (captcha: any, pageUrl: any, extraData: any, options: any, callback: any) => void; | ||
export declare const decodeUrl: (uri: any, options: any, callback: any) => void; | ||
export declare const solveRecaptchaFromHtml: (html: any, options: any, callback: any) => any; | ||
export declare const report: (captchaId: any) => void; |
@@ -18,3 +18,3 @@ "use strict"; | ||
pollingInterval: 2000, | ||
retries: 3 | ||
retries: 3, | ||
}; | ||
@@ -48,3 +48,3 @@ function pollCaptcha(captchaId, options, invalid, callback) { | ||
id: captchaId, | ||
text: result[1] | ||
text: result[1], | ||
}, invalid); | ||
@@ -72,3 +72,3 @@ } | ||
soft_id: SOFT_ID, | ||
body: base64 | ||
body: base64, | ||
}; | ||
@@ -108,3 +108,3 @@ postData = querystring.stringify(postData); | ||
}; | ||
exports.decodeReCaptcha = function (captcha, pageUrl, options, callback) { | ||
exports.decodeReCaptcha = function (captcha, pageUrl, extraData, options, callback) { | ||
if (!callback) { | ||
@@ -116,9 +116,3 @@ callback = options; | ||
httpRequestOptions.method = 'POST'; | ||
var postData = { | ||
method: apiMethodRecaptcha, | ||
key: apiKey, | ||
soft_id: SOFT_ID, | ||
googlekey: captcha, | ||
pageurl: pageUrl | ||
}; | ||
var postData = Object.assign({ method: apiMethodRecaptcha, key: apiKey, soft_id: SOFT_ID, googlekey: captcha, pageurl: pageUrl }, extraData); | ||
postData = querystring.stringify(postData); | ||
@@ -125,0 +119,0 @@ var request = http.request(httpRequestOptions, function (response) { |
@@ -32,8 +32,8 @@ "use strict"; | ||
const secondsBetweenDates = (before, after) => (after.getTime() - before.getTime()) / 1000; | ||
async function decodeRecaptchaAsync(token, sitekey, url, opts = { pollingInterval: 2000 }) { | ||
return new Promise(resolve => { | ||
async function decodeRecaptchaAsync(token, sitekey, url, extraData, opts = { pollingInterval: 2000 }) { | ||
return new Promise((resolve) => { | ||
const cb = (err, result, invalid) => resolve({ err, result, invalid }); | ||
try { | ||
solver.setApiKey(token); | ||
solver.decodeReCaptcha(sitekey, url, opts, cb); | ||
solver.decodeReCaptcha(sitekey, url, extraData, opts, cb); | ||
} | ||
@@ -46,4 +46,4 @@ catch (error) { | ||
async function getSolutions(captchas = [], token) { | ||
const solutions = await Promise.all(captchas.map(c => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find(s => !!s.error) }; | ||
const solutions = await Promise.all(captchas.map((c) => getSolution(c, token || ''))); | ||
return { solutions, error: solutions.find((s) => !!s.error) }; | ||
} | ||
@@ -53,3 +53,3 @@ exports.getSolutions = getSolutions; | ||
const solution = { | ||
provider: exports.PROVIDER_ID | ||
provider: exports.PROVIDER_ID, | ||
}; | ||
@@ -63,3 +63,7 @@ try { | ||
debug('Requesting solution..', solution); | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url); | ||
const extraData = {}; | ||
if (captcha.s) { | ||
extraData['data-s'] = captcha.s; // google site specific property | ||
} | ||
const { err, result, invalid } = await decodeRecaptchaAsync(token, captcha.sitekey, captcha.url, extraData); | ||
debug('Got response', { err, result, invalid }); | ||
@@ -66,0 +70,0 @@ if (err) |
@@ -43,2 +43,3 @@ /// <reference path="../dist/puppeteer-mods.d.ts" /> | ||
sitekey?: string; | ||
s?: string; | ||
callback?: string | Function; | ||
@@ -45,0 +46,0 @@ hasResponseElement?: boolean; |
{ | ||
"name": "puppeteer-extra-plugin-recaptcha", | ||
"version": "3.1.19", | ||
"version": "3.2.0", | ||
"description": "A puppeteer-extra plugin to solve reCAPTCHAs automatically.", | ||
@@ -73,3 +73,3 @@ "main": "dist/index.cjs.js", | ||
}, | ||
"gitHead": "223f01d295a0b3b88397a3269d796e078aa79dbe" | ||
"gitHead": "08b00f7c59c28f3fed379ded93d1391f68e1489d" | ||
} |
@@ -26,2 +26,8 @@ # 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) | ||
##### Latest | ||
> 🎁 **Note:** Until we've automated changelog updates in markdown files please follow the `#announcements` channel in our [discord server](https://discord.gg/vz7PeKk) for the latest updates and changelog info. | ||
_Older changelog:_ | ||
##### `3.1.9` | ||
@@ -71,5 +77,5 @@ | ||
id: '2captcha', | ||
token: 'XXXXXXX' // REPLACE THIS WITH YOUR OWN 2CAPTCHA API KEY ⚡ | ||
token: 'XXXXXXX', // REPLACE THIS WITH YOUR OWN 2CAPTCHA API KEY ⚡ | ||
}, | ||
visualFeedback: true // colorize reCAPTCHAs (violet = detected, green = solved) | ||
visualFeedback: true, // colorize reCAPTCHAs (violet = detected, green = solved) | ||
}) | ||
@@ -79,3 +85,3 @@ ) | ||
// puppeteer usage as normal | ||
puppeteer.launch({ headless: true }).then(async browser => { | ||
puppeteer.launch({ headless: true }).then(async (browser) => { | ||
const page = await browser.newPage() | ||
@@ -89,3 +95,3 @@ await page.goto('https://www.google.com/recaptcha/api2/demo') | ||
page.waitForNavigation(), | ||
page.click(`#recaptcha-demo-submit`) | ||
page.click(`#recaptcha-demo-submit`), | ||
]) | ||
@@ -111,4 +117,4 @@ await page.screenshot({ path: 'response.png', fullPage: true }) | ||
id: '2captcha', | ||
token: 'ENTER_YOUR_2CAPTCHA_API_KEY_HERE' | ||
} | ||
token: 'ENTER_YOUR_2CAPTCHA_API_KEY_HERE', | ||
}, | ||
}) | ||
@@ -118,3 +124,3 @@ ) | ||
// Puppeteer usage as normal (headless is "false" just for this demo) | ||
puppeteer.launch({ headless: false }).then(async browser => { | ||
puppeteer.launch({ headless: false }).then(async (browser) => { | ||
const page = await browser.newPage() | ||
@@ -128,3 +134,3 @@ await page.goto('https://www.google.com/recaptcha/api2/demo') | ||
page.waitForNavigation(), | ||
page.click(`#recaptcha-demo-submit`) | ||
page.click(`#recaptcha-demo-submit`), | ||
]) | ||
@@ -131,0 +137,0 @@ await page.screenshot({ path: 'response.png', fullPage: true }) |
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
237162
2518
251