4
4
*/
5
5
import { getAuthHeader , registerDevice } from '../auth' ;
6
6
import { PROXY_URL , BROWSER_URL , TIME_URL } from '../constant' ;
7
+ import { logger } from '../logger' ;
7
8
8
9
const FREE_TRIAL_DURATION_MS = 30 * 60 * 1000 ;
9
10
@@ -26,7 +27,7 @@ async function fetchWithAuth(
26
27
return response . json ( ) ;
27
28
} catch ( error ) {
28
29
if ( retries <= 0 ) throw error ;
29
- console . error ( `[proxyClient] Retrying request...` ) ;
30
+ logger . error ( `[proxyClient] Retrying request...` ) ;
30
31
return fetchWithAuth ( url , options , retries - 1 ) ;
31
32
}
32
33
}
@@ -49,9 +50,12 @@ export class RemoteComputer {
49
50
PositionY : y ,
50
51
} ) ,
51
52
} ) ;
52
- console . log ( 'Move Mouse Response:' , data ) ;
53
+ logger . log ( '[RemoteComputer] Move Mouse Response:' , data ) ;
53
54
} catch ( error ) {
54
- console . error ( 'Move Mouse Error:' , ( error as Error ) . message ) ;
55
+ logger . error (
56
+ '[RemoteComputer] Move Mouse Error:' ,
57
+ ( error as Error ) . message ,
58
+ ) ;
55
59
throw error ;
56
60
}
57
61
}
@@ -76,9 +80,12 @@ export class RemoteComputer {
76
80
Release : release ,
77
81
} ) ,
78
82
} ) ;
79
- console . log ( 'Click Mouse Response:' , data ) ;
83
+ logger . log ( '[RemoteComputer] Click Mouse Response:' , data ) ;
80
84
} catch ( error ) {
81
- console . error ( 'Click Mouse Error:' , ( error as Error ) . message ) ;
85
+ logger . error (
86
+ '[RemoteComputer] Click Mouse Error:' ,
87
+ ( error as Error ) . message ,
88
+ ) ;
82
89
throw error ;
83
90
}
84
91
}
@@ -101,9 +108,12 @@ export class RemoteComputer {
101
108
TargetY : targetY ,
102
109
} ) ,
103
110
} ) ;
104
- console . log ( 'Drag Mouse Response:' , data ) ;
111
+ logger . log ( '[RemoteComputer] Drag Mouse Response:' , data ) ;
105
112
} catch ( error ) {
106
- console . error ( 'Drag Mouse Error:' , ( error as Error ) . message ) ;
113
+ logger . error (
114
+ '[RemoteComputer] Drag Mouse Error:' ,
115
+ ( error as Error ) . message ,
116
+ ) ;
107
117
throw error ;
108
118
}
109
119
}
@@ -118,9 +128,12 @@ export class RemoteComputer {
118
128
Key : key ,
119
129
} ) ,
120
130
} ) ;
121
- console . log ( 'Press Key Response:' , data ) ;
131
+ logger . log ( '[RemoteComputer] Press Key Response:' , data ) ;
122
132
} catch ( error ) {
123
- console . error ( 'Press Key Error:' , ( error as Error ) . message ) ;
133
+ logger . error (
134
+ '[RemoteComputer] Press Key Error:' ,
135
+ ( error as Error ) . message ,
136
+ ) ;
124
137
throw error ;
125
138
}
126
139
}
@@ -135,9 +148,12 @@ export class RemoteComputer {
135
148
Text : text ,
136
149
} ) ,
137
150
} ) ;
138
- console . log ( 'Type Text Response:' , data ) ;
151
+ logger . log ( '[RemoteComputer] Type Text Response:' , data ) ;
139
152
} catch ( error ) {
140
- console . error ( 'Type Text Error:' , ( error as Error ) . message ) ;
153
+ logger . error (
154
+ '[RemoteComputer] Type Text Error:' ,
155
+ ( error as Error ) . message ,
156
+ ) ;
141
157
throw error ;
142
158
}
143
159
}
@@ -160,9 +176,9 @@ export class RemoteComputer {
160
176
Amount : Math . min ( amount , 10 ) ,
161
177
} ) ,
162
178
} ) ;
163
- console . log ( 'Scroll Response:' , data ) ;
179
+ logger . log ( '[RemoteComputer] Scroll Response:' , data ) ;
164
180
} catch ( error ) {
165
- console . error ( 'Scroll Error:' , ( error as Error ) . message ) ;
181
+ logger . error ( '[RemoteComputer] Scroll Error:' , ( error as Error ) . message ) ;
166
182
throw error ;
167
183
}
168
184
}
@@ -180,12 +196,15 @@ export class RemoteComputer {
180
196
const { Result } = data ;
181
197
if ( Result ) {
182
198
const { Width, Height } = Result ;
183
- console . log ( 'Screen size:' , Result ) ;
199
+ logger . log ( '[RemoteComputer] Screen size:' , Result ) ;
184
200
return { width : Width , height : Height } ;
185
201
}
186
202
throw new Error ( 'Failed to get screen size' ) ;
187
203
} catch ( error ) {
188
- console . error ( 'Get Screen Size Error:' , ( error as Error ) . message ) ;
204
+ logger . error (
205
+ '[RemoteComputer] Get Screen Size Error:' ,
206
+ ( error as Error ) . message ,
207
+ ) ;
189
208
throw error ;
190
209
}
191
210
}
@@ -204,8 +223,8 @@ export class RemoteComputer {
204
223
const duration = endTime - startTime ;
205
224
206
225
const { ResponseMetadata, Result } = data ;
207
- console . log ( 'Take Screenshot Response:' , ResponseMetadata ) ;
208
- console . log ( 'The time consumed:' , duration , 'ms' ) ;
226
+ logger . log ( '[RemoteComputer] TakeScreenshot Response:' , ResponseMetadata ) ;
227
+ logger . log ( '[RemoteComputer] The time consumed:' , duration , 'ms' ) ;
209
228
210
229
if ( Result ?. Screenshot ) {
211
230
const base64Data = Result . Screenshot . replace (
@@ -216,7 +235,10 @@ export class RemoteComputer {
216
235
}
217
236
throw new Error ( 'Screenshot data not found in response' ) ;
218
237
} catch ( error ) {
219
- console . error ( 'Take Screenshot Error:' , ( error as Error ) . message ) ;
238
+ logger . error (
239
+ '[RemoteComputer] TakeScreenshot Error:' ,
240
+ ( error as Error ) . message ,
241
+ ) ;
220
242
throw error ;
221
243
}
222
244
}
@@ -366,7 +388,7 @@ export class ProxyClient {
366
388
}
367
389
const sandboxId = this . instance . sandboxInfo . sandBoxId ;
368
390
const rdpUrl = this . instance . describeSandboxTerminalUrl ( sandboxId ) ;
369
- console . log ( 'getSandboxRDPUrl' , rdpUrl ) ;
391
+ logger . log ( '[ProxyClient] getSandboxRDPUrl successful' ) ;
370
392
return rdpUrl ;
371
393
}
372
394
@@ -382,7 +404,7 @@ export class ProxyClient {
382
404
}
383
405
384
406
const cdpUrlNew = await this . instance . getAvaliableWsCDPUrl ( browserId ) ;
385
- console . log ( 'getBrowserCDPUrl refresh: ' , cdpUrlNew ) ;
407
+ logger . log ( '[ProxyClient] getBrowserCDPUrl refresh: ' , cdpUrlNew ) ;
386
408
if ( cdpUrlNew != null ) {
387
409
this . instance . browserInfo . wsUrl = cdpUrlNew ;
388
410
return cdpUrlNew ;
@@ -395,7 +417,10 @@ export class ProxyClient {
395
417
const timeBalance = await this . instance . timeBalance ( 'GET' ) ;
396
418
return timeBalance ;
397
419
} catch ( error ) {
398
- console . error ( 'Get Time Balance Error:' , ( error as Error ) . message ) ;
420
+ logger . error (
421
+ '[ProxyClient] Get Time Balance Error:' ,
422
+ ( error as Error ) . message ,
423
+ ) ;
399
424
return - 1 ;
400
425
}
401
426
}
@@ -405,7 +430,10 @@ export class ProxyClient {
405
430
const timeBalance = await this . instance . timeBalance ( 'PATCH' ) ;
406
431
return timeBalance ;
407
432
} catch ( error ) {
408
- console . error ( 'Get Time Balance Error:' , ( error as Error ) . message ) ;
433
+ logger . error (
434
+ '[ProxyClient] Get Time Balance Error:' ,
435
+ ( error as Error ) . message ,
436
+ ) ;
409
437
return - 1 ;
410
438
}
411
439
}
@@ -433,12 +461,12 @@ export class ProxyClient {
433
461
method : 'GET' ,
434
462
headers : { 'Content-Type' : 'application/json' } ,
435
463
} ) ;
436
- console . log ( 'Describe Avaliable Sandbox Response:' , data ) ;
464
+ logger . log ( '[ProxyClient] Describe Avaliable Sandbox Response:' , data ) ;
437
465
438
466
return data ;
439
467
} catch ( error ) {
440
- console . error (
441
- 'Describe Avaliable Sandbox Error:' ,
468
+ logger . error (
469
+ '[ProxyClient] Describe Avaliable Sandbox Error:' ,
442
470
( error as Error ) . message ,
443
471
) ;
444
472
throw error ;
@@ -454,11 +482,11 @@ export class ProxyClient {
454
482
headers : { 'Content-Type' : 'application/json' } ,
455
483
} ,
456
484
) ;
457
- console . log ( 'Describe Avaliable Browser Response:' , data ) ;
485
+ logger . log ( '[ProxyClient] Describe Avaliable Browser Response:' , data ) ;
458
486
return data ;
459
487
} catch ( error ) {
460
- console . error (
461
- 'Describe Avaliable Browser Error:' ,
488
+ logger . error (
489
+ '[ProxyClient] Describe Avaliable Browser Error:' ,
462
490
( error as Error ) . message ,
463
491
) ;
464
492
throw error ;
@@ -479,10 +507,13 @@ export class ProxyClient {
479
507
SandboxId : sandboxId ,
480
508
} ) ,
481
509
} ) ;
482
- console . log ( 'Release Sandbox Response:' , data ) ;
510
+ logger . log ( '[ProxyClient] Release Sandbox Response:' , data ) ;
483
511
return true ;
484
512
} catch ( error ) {
485
- console . error ( 'Release Sandbox Error:' , ( error as Error ) . message ) ;
513
+ logger . error (
514
+ '[ProxyClient] Release Sandbox Error:' ,
515
+ ( error as Error ) . message ,
516
+ ) ;
486
517
throw error ;
487
518
}
488
519
}
@@ -500,10 +531,13 @@ export class ProxyClient {
500
531
BrowserId : browserId ,
501
532
} ) ,
502
533
} ) ;
503
- console . log ( 'Release Browser Response:' , data ) ;
534
+ logger . log ( '[ProxyClient] Release Browser Response:' , data ) ;
504
535
return true ;
505
536
} catch ( error ) {
506
- console . error ( 'Release Browser Error:' , ( error as Error ) . message ) ;
537
+ logger . error (
538
+ '[ProxyClient] Release Browser Error:' ,
539
+ ( error as Error ) . message ,
540
+ ) ;
507
541
throw error ;
508
542
}
509
543
}
@@ -514,10 +548,13 @@ export class ProxyClient {
514
548
method : method ,
515
549
headers : { 'Content-Type' : 'application/json' } ,
516
550
} ) ;
517
- console . log ( 'timeBalance() Response:' , data ) ;
551
+ logger . log ( '[ProxyClient] timeBalance Response:' , data ) ;
518
552
return data . balance ;
519
553
} catch ( error ) {
520
- console . error ( 'timeBalance() Error:' , ( error as Error ) . message ) ;
554
+ logger . error (
555
+ '[ProxyClient] timeBalance Error:' ,
556
+ ( error as Error ) . message ,
557
+ ) ;
521
558
throw error ;
522
559
}
523
560
}
@@ -582,14 +619,14 @@ export class ProxyClient {
582
619
SandboxId : sandboxId ,
583
620
} ) ,
584
621
} ) ;
585
- console . log ( 'Describe Sandbox Terminal URL Response:' , data ) ;
622
+ logger . log ( '[ProxyClient] Describe Sandbox Terminal URL Response:' , data ) ;
586
623
587
624
const { rdpUrl } = data ;
588
625
589
626
return rdpUrl ;
590
627
} catch ( error ) {
591
- console . error (
592
- 'Describe Sandbox Terminal URL Error:' ,
628
+ logger . error (
629
+ '[ProxyClient] Describe Sandbox Terminal URL Error:' ,
593
630
( error as Error ) . message ,
594
631
) ;
595
632
throw error ;
@@ -602,11 +639,11 @@ export class ProxyClient {
602
639
method : 'GET' ,
603
640
headers : { 'Content-Type' : 'application/json' } ,
604
641
} ) ;
605
- console . log ( 'Describe Browsers Response:' , data ) ;
642
+ logger . log ( '[ProxyClient] Describe Browsers Response:' , data ) ;
606
643
607
644
const browsersRet : Browser [ ] = [ ] ;
608
645
for ( const [ podName , browsers ] of Object . entries ( data ) ) {
609
- console . log ( 'Pod:' , podName ) ;
646
+ logger . log ( '[ProxyClient] Pod:' , podName ) ;
610
647
( browsers as BrowserInternal [ ] ) . forEach ( ( browser ) => {
611
648
if ( browser . status === 'ready' ) {
612
649
browsersRet . push ( {
@@ -621,7 +658,10 @@ export class ProxyClient {
621
658
}
622
659
return browsersRet ;
623
660
} catch ( error ) {
624
- console . error ( 'Describe Browsers Error:' , ( error as Error ) . message ) ;
661
+ logger . error (
662
+ '[ProxyClient] Describe Browsers Error:' ,
663
+ ( error as Error ) . message ,
664
+ ) ;
625
665
throw error ;
626
666
}
627
667
}
0 commit comments