@@ -7,6 +7,11 @@ export type LoginEvent =
7
7
| "manual-otp-required"
8
8
| "unexpected" ;
9
9
10
+ export interface CaptchaStatus {
11
+ readonly imageData : string ;
12
+ readonly question : string ;
13
+ }
14
+
10
15
export default class PageInteractor {
11
16
private _fullyLoaded = false ;
12
17
@@ -27,9 +32,9 @@ export default class PageInteractor {
27
32
28
33
private async typeLoginInfo ( id : string , password : string , delay : number ) {
29
34
await this . page . focus ( "#id" ) ;
30
- await this . page . keyboard . type ( id , { delay : delay || 200 } ) ;
35
+ await this . page . keyboard . type ( id , { delay : delay } ) ;
31
36
await this . page . focus ( "#pw" ) ;
32
- await this . page . keyboard . type ( password , { delay : delay || 200 } ) ;
37
+ await this . page . keyboard . type ( password , { delay : delay } ) ;
33
38
await this . clickLoginButton ( ) ;
34
39
}
35
40
@@ -83,6 +88,38 @@ export default class PageInteractor {
83
88
await manualOTPElement . press ( "Enter" ) ;
84
89
}
85
90
91
+ async getCaptchaStatus ( ) : Promise < CaptchaStatus | null > {
92
+ const data = await this . page . evaluate ( ( ) => {
93
+ const captchaImage = document . querySelector (
94
+ "#captchaimg"
95
+ ) as HTMLElement | null ;
96
+ const captchaText = document . querySelector (
97
+ "#captcha_info"
98
+ ) as HTMLElement | null ;
99
+
100
+ if ( ! captchaImage || ! captchaText ) {
101
+ return ;
102
+ }
103
+
104
+ const imageData = captchaImage . getAttribute ( "src" ) as string ;
105
+ const question = captchaText . innerText ;
106
+
107
+ return { imageData, question } ;
108
+ } ) ;
109
+
110
+ return data || null ;
111
+ }
112
+
113
+ async fillCaptchaInput ( answer : string , password : string ) {
114
+ const captchaElement = await this . elementParser . parseCaptchaInputElement ( ) ;
115
+ if ( ! captchaElement ) {
116
+ throw new Error ( "captcha input element not found" ) ;
117
+ }
118
+ await captchaElement . type ( answer ) ;
119
+
120
+ await this . typeLoginInfo ( "" , password , 200 ) ;
121
+ }
122
+
86
123
async loadMoreHistory ( ) {
87
124
if ( this . _fullyLoaded ) {
88
125
return ;
0 commit comments