@@ -54,7 +54,8 @@ const solveCaptcha = async (params = {}) => {
54
54
const defaultParams = {
55
55
type : 'recaptcha' ,
56
56
timeout : DEFAULT_TIMEOUT ,
57
- withFullSolution : false
57
+ withFullSolution : false ,
58
+ requestInstance : request
58
59
}
59
60
let solution
60
61
let resultAttribute = 'gRecaptchaResponse'
@@ -69,7 +70,8 @@ const solveCaptcha = async (params = {}) => {
69
70
solution = await solveWithAntiCaptcha (
70
71
{ websiteKey, websiteURL, type : 'NoCaptchaTaskProxyless' } ,
71
72
params . timeout ,
72
- secrets
73
+ secrets ,
74
+ params
73
75
)
74
76
} else if ( params . type === 'recaptchav3' ) {
75
77
checkMandatoryParams ( params , [
@@ -88,7 +90,8 @@ const solveCaptcha = async (params = {}) => {
88
90
type : 'RecaptchaV3TaskProxyless'
89
91
} ,
90
92
params . timeout ,
91
- secrets
93
+ secrets ,
94
+ params
92
95
)
93
96
} else if ( params . type === 'hcaptcha' ) {
94
97
checkMandatoryParams ( params , [ 'websiteKey' , 'websiteURL' ] )
@@ -100,7 +103,8 @@ const solveCaptcha = async (params = {}) => {
100
103
type : 'HCaptchaTaskProxyless'
101
104
} ,
102
105
params . timeout ,
103
- secrets
106
+ secrets ,
107
+ params
104
108
)
105
109
} else if ( params . type === 'image' ) {
106
110
checkMandatoryParams ( params , [ 'body' ] )
@@ -109,7 +113,8 @@ const solveCaptcha = async (params = {}) => {
109
113
solution = await solveWithAntiCaptcha (
110
114
{ body : params . body , type : 'ImageToTextTask' } ,
111
115
params . timeout ,
112
- secrets
116
+ secrets ,
117
+ params
113
118
)
114
119
}
115
120
if ( params . withFullSolution ) {
@@ -132,7 +137,8 @@ function checkMandatoryParams(params = {}, mandatoryParams = []) {
132
137
async function solveWithAntiCaptcha (
133
138
taskParams ,
134
139
timeout = DEFAULT_TIMEOUT ,
135
- secrets
140
+ secrets ,
141
+ params
136
142
) {
137
143
const antiCaptchaApiUrl = 'https://api.anti-captcha.com'
138
144
let gRecaptchaResponse = null
@@ -142,23 +148,29 @@ async function solveWithAntiCaptcha(
142
148
const clientKey = secrets . antiCaptchaClientKey
143
149
if ( clientKey ) {
144
150
log ( 'debug' , ' Creating captcha resolution task...' )
145
- const task = await request . post ( `${ antiCaptchaApiUrl } /createTask` , {
146
- body : {
147
- clientKey,
148
- task : taskParams
149
- } ,
150
- json : true
151
- } )
151
+ const task = await params . requestInstance . post (
152
+ `${ antiCaptchaApiUrl } /createTask` ,
153
+ {
154
+ body : {
155
+ clientKey,
156
+ task : taskParams
157
+ } ,
158
+ json : true
159
+ }
160
+ )
152
161
if ( task && task . taskId ) {
153
162
log ( 'debug' , ` Task id : ${ task . taskId } ` )
154
163
while ( ! gRecaptchaResponse ) {
155
- const resp = await request . post ( `${ antiCaptchaApiUrl } /getTaskResult` , {
156
- body : {
157
- clientKey,
158
- taskId : task . taskId
159
- } ,
160
- json : true
161
- } )
164
+ const resp = await params . requestInstance . post (
165
+ `${ antiCaptchaApiUrl } /getTaskResult` ,
166
+ {
167
+ body : {
168
+ clientKey,
169
+ taskId : task . taskId
170
+ } ,
171
+ json : true
172
+ }
173
+ )
162
174
if ( resp . status === 'ready' ) {
163
175
if ( resp . errorId ) {
164
176
log ( 'error' , `Anticaptcha error: ${ JSON . stringify ( resp ) } ` )
0 commit comments