@appium/base-driver 10.6.0 → 10.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/basedriver/capabilities.d.ts +1 -1
- package/build/lib/basedriver/capabilities.d.ts.map +1 -1
- package/build/lib/basedriver/capabilities.js +15 -7
- package/build/lib/basedriver/capabilities.js.map +1 -1
- package/build/lib/basedriver/commands/bidi.js +1 -1
- package/build/lib/basedriver/commands/event.js.map +1 -1
- package/build/lib/basedriver/commands/execute.js.map +1 -1
- package/build/lib/basedriver/commands/find.d.ts.map +1 -1
- package/build/lib/basedriver/commands/find.js +2 -1
- package/build/lib/basedriver/commands/find.js.map +1 -1
- package/build/lib/basedriver/commands/timeout.js +4 -4
- package/build/lib/basedriver/commands/timeout.js.map +1 -1
- package/build/lib/basedriver/core.d.ts.map +1 -1
- package/build/lib/basedriver/core.js +5 -2
- package/build/lib/basedriver/core.js.map +1 -1
- package/build/lib/basedriver/device-settings.d.ts.map +1 -1
- package/build/lib/basedriver/device-settings.js.map +1 -1
- package/build/lib/basedriver/driver.d.ts.map +1 -1
- package/build/lib/basedriver/driver.js +23 -24
- package/build/lib/basedriver/driver.js.map +1 -1
- package/build/lib/basedriver/extension-core.d.ts.map +1 -1
- package/build/lib/basedriver/extension-core.js +11 -5
- package/build/lib/basedriver/extension-core.js.map +1 -1
- package/build/lib/basedriver/helpers.d.ts.map +1 -1
- package/build/lib/basedriver/helpers.js +20 -4
- package/build/lib/basedriver/helpers.js.map +1 -1
- package/build/lib/basedriver/ipc.d.ts.map +1 -1
- package/build/lib/basedriver/ipc.js +6 -4
- package/build/lib/basedriver/ipc.js.map +1 -1
- package/build/lib/basedriver/validation.d.ts.map +1 -1
- package/build/lib/basedriver/validation.js +3 -2
- package/build/lib/basedriver/validation.js.map +1 -1
- package/build/lib/express/express-logging.d.ts +0 -1
- package/build/lib/express/express-logging.d.ts.map +1 -1
- package/build/lib/express/express-logging.js +9 -8
- package/build/lib/express/express-logging.js.map +1 -1
- package/build/lib/express/idempotency.js.map +1 -1
- package/build/lib/express/middleware.d.ts.map +1 -1
- package/build/lib/express/middleware.js.map +1 -1
- package/build/lib/express/server.d.ts +1 -1
- package/build/lib/express/server.d.ts.map +1 -1
- package/build/lib/express/server.js +19 -20
- package/build/lib/express/server.js.map +1 -1
- package/build/lib/express/websocket.d.ts.map +1 -1
- package/build/lib/express/websocket.js.map +1 -1
- package/build/lib/helpers/capabilities.d.ts.map +1 -1
- package/build/lib/helpers/capabilities.js.map +1 -1
- package/build/lib/helpers/levenshtein-match.d.ts.map +1 -1
- package/build/lib/helpers/levenshtein-match.js +4 -1
- package/build/lib/helpers/levenshtein-match.js.map +1 -1
- package/build/lib/index.d.ts +1 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js +3 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/protocol-converter.js +14 -7
- package/build/lib/jsonwp-proxy/protocol-converter.js.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.d.ts.map +1 -1
- package/build/lib/jsonwp-proxy/proxy.js +17 -11
- package/build/lib/jsonwp-proxy/proxy.js.map +1 -1
- package/build/lib/protocol/errors.d.ts.map +1 -1
- package/build/lib/protocol/errors.js +13 -13
- package/build/lib/protocol/errors.js.map +1 -1
- package/build/lib/protocol/protocol.d.ts +1 -1
- package/build/lib/protocol/protocol.d.ts.map +1 -1
- package/build/lib/protocol/protocol.js +35 -18
- package/build/lib/protocol/protocol.js.map +1 -1
- package/build/lib/protocol/routes.d.ts.map +1 -1
- package/build/lib/protocol/routes.js +7 -5
- package/build/lib/protocol/routes.js.map +1 -1
- package/build/lib/test-pages/crash.d.ts.map +1 -0
- package/build/lib/test-pages/crash.js.map +1 -0
- package/build/lib/test-pages/env.d.ts +5 -0
- package/build/lib/test-pages/env.d.ts.map +1 -0
- package/build/lib/test-pages/env.js +12 -0
- package/build/lib/test-pages/env.js.map +1 -0
- package/build/lib/{express/static.d.ts → test-pages/handlers.d.ts} +1 -2
- package/build/lib/test-pages/handlers.d.ts.map +1 -0
- package/build/lib/{express/static.js → test-pages/handlers.js} +7 -17
- package/build/lib/test-pages/handlers.js.map +1 -0
- package/build/lib/test-pages/index.d.ts +6 -0
- package/build/lib/test-pages/index.d.ts.map +1 -0
- package/build/lib/test-pages/index.js +35 -0
- package/build/lib/test-pages/index.js.map +1 -0
- package/build/lib/test-pages/static-dir.d.ts +8 -0
- package/build/lib/test-pages/static-dir.d.ts.map +1 -0
- package/build/lib/test-pages/static-dir.js +24 -0
- package/build/lib/test-pages/static-dir.js.map +1 -0
- package/build/lib/test-pages/template.d.ts +3 -0
- package/build/lib/test-pages/template.d.ts.map +1 -0
- package/build/lib/test-pages/template.js +19 -0
- package/build/lib/test-pages/template.js.map +1 -0
- package/build/lib/utils.d.ts +0 -2
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +0 -16
- package/build/lib/utils.js.map +1 -1
- package/lib/basedriver/capabilities.ts +72 -66
- package/lib/basedriver/commands/bidi.ts +1 -1
- package/lib/basedriver/commands/event.ts +10 -5
- package/lib/basedriver/commands/execute.ts +12 -9
- package/lib/basedriver/commands/find.ts +20 -12
- package/lib/basedriver/commands/log.ts +2 -2
- package/lib/basedriver/commands/timeout.ts +17 -8
- package/lib/basedriver/core.ts +14 -14
- package/lib/basedriver/device-settings.ts +4 -8
- package/lib/basedriver/driver.ts +50 -40
- package/lib/basedriver/extension-core.ts +33 -17
- package/lib/basedriver/helpers.ts +57 -26
- package/lib/basedriver/ipc.ts +37 -18
- package/lib/basedriver/validation.ts +13 -6
- package/lib/express/express-logging.ts +14 -17
- package/lib/express/idempotency.ts +6 -6
- package/lib/express/middleware.ts +10 -12
- package/lib/express/server.ts +53 -61
- package/lib/express/websocket.ts +5 -7
- package/lib/helpers/capabilities.ts +5 -4
- package/lib/helpers/extension-command-name.ts +1 -1
- package/lib/helpers/levenshtein-match.ts +20 -11
- package/lib/index.js +2 -1
- package/lib/jsonwp-proxy/protocol-converter.ts +51 -27
- package/lib/jsonwp-proxy/proxy.ts +42 -42
- package/lib/protocol/errors.ts +47 -67
- package/lib/protocol/protocol.ts +116 -72
- package/lib/protocol/routes.ts +9 -9
- package/lib/test-pages/env.ts +9 -0
- package/lib/{express/static.ts → test-pages/handlers.ts} +7 -27
- package/lib/test-pages/index.ts +34 -0
- package/lib/test-pages/static-dir.ts +19 -0
- package/lib/test-pages/template.ts +17 -0
- package/lib/utils.ts +3 -23
- package/package.json +9 -10
- package/tsconfig.json +1 -0
- package/build/lib/express/crash.d.ts.map +0 -1
- package/build/lib/express/crash.js.map +0 -1
- package/build/lib/express/static.d.ts.map +0 -1
- package/build/lib/express/static.js.map +0 -1
- /package/build/lib/{express → test-pages}/crash.d.ts +0 -0
- /package/build/lib/{express → test-pages}/crash.js +0 -0
- /package/lib/{express → test-pages}/crash.ts +0 -0
- /package/{static → test-fixtures/static}/appium.png +0 -0
- /package/{static → test-fixtures/static}/favicon.ico +0 -0
- /package/{static → test-fixtures/static}/js/jquery.min.js +0 -0
- /package/{static → test-fixtures/static}/test/frameset.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-app-banner.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig-scrollable.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig2.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig3.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig4.html +0 -0
- /package/{static → test-fixtures/static}/test/guinea-pig5.html +0 -0
- /package/{static → test-fixtures/static}/test/iframes.html +0 -0
- /package/{static → test-fixtures/static}/test/shadow-dom.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe1.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe2.html +0 -0
- /package/{static → test-fixtures/static}/test/subframe3.html +0 -0
- /package/{static → test-fixtures/static}/test/touch.html +0 -0
- /package/{static → test-fixtures/static}/test/welcome.html +0 -0
package/lib/protocol/errors.ts
CHANGED
|
@@ -76,7 +76,7 @@ export class ProtocolError extends BaseError {
|
|
|
76
76
|
bidiErrObject(id: string | number): ErrorBiDiCommandResponse {
|
|
77
77
|
// if we don't have an id, the client didn't send one, so we have nothing to send back.
|
|
78
78
|
// send back zero rather than making something up
|
|
79
|
-
const intId = (Number.isInteger(id) ? id :
|
|
79
|
+
const intId = (Number.isInteger(id) ? id : parseInt(`${id}`, 10) || 0) as number;
|
|
80
80
|
return {
|
|
81
81
|
id: intId,
|
|
82
82
|
type: 'error',
|
|
@@ -112,7 +112,6 @@ export class NoSuchDriverError extends ProtocolError {
|
|
|
112
112
|
static error() {
|
|
113
113
|
return 'invalid session id';
|
|
114
114
|
}
|
|
115
|
-
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
export class NoSuchElementError extends ProtocolError {
|
|
@@ -136,7 +135,6 @@ export class NoSuchElementError extends ProtocolError {
|
|
|
136
135
|
static error() {
|
|
137
136
|
return 'no such element';
|
|
138
137
|
}
|
|
139
|
-
|
|
140
138
|
}
|
|
141
139
|
|
|
142
140
|
/**
|
|
@@ -148,8 +146,7 @@ export class NoSuchElementError extends ProtocolError {
|
|
|
148
146
|
export class NoSuchShadowRootError extends ProtocolError {
|
|
149
147
|
constructor(message: string = '', cause?: Error) {
|
|
150
148
|
super(
|
|
151
|
-
message ||
|
|
152
|
-
'The element does not have a shadow root attached.',
|
|
149
|
+
message || 'The element does not have a shadow root attached.',
|
|
153
150
|
NoSuchShadowRootError.code(),
|
|
154
151
|
NoSuchShadowRootError.w3cStatus(),
|
|
155
152
|
NoSuchShadowRootError.error(),
|
|
@@ -169,7 +166,6 @@ export class NoSuchShadowRootError extends ProtocolError {
|
|
|
169
166
|
static w3cStatus() {
|
|
170
167
|
return HTTPStatusCodes.NOT_FOUND;
|
|
171
168
|
}
|
|
172
|
-
|
|
173
169
|
}
|
|
174
170
|
|
|
175
171
|
export class NoSuchFrameError extends ProtocolError {
|
|
@@ -194,7 +190,6 @@ export class NoSuchFrameError extends ProtocolError {
|
|
|
194
190
|
static w3cStatus() {
|
|
195
191
|
return HTTPStatusCodes.NOT_FOUND;
|
|
196
192
|
}
|
|
197
|
-
|
|
198
193
|
}
|
|
199
194
|
|
|
200
195
|
export class UnknownCommandError extends ProtocolError {
|
|
@@ -220,7 +215,6 @@ export class UnknownCommandError extends ProtocolError {
|
|
|
220
215
|
static error() {
|
|
221
216
|
return 'unknown command';
|
|
222
217
|
}
|
|
223
|
-
|
|
224
218
|
}
|
|
225
219
|
|
|
226
220
|
export class StaleElementReferenceError extends ProtocolError {
|
|
@@ -245,7 +239,6 @@ export class StaleElementReferenceError extends ProtocolError {
|
|
|
245
239
|
static error() {
|
|
246
240
|
return 'stale element reference';
|
|
247
241
|
}
|
|
248
|
-
|
|
249
242
|
}
|
|
250
243
|
|
|
251
244
|
export class ElementNotVisibleError extends ProtocolError {
|
|
@@ -270,7 +263,6 @@ export class ElementNotVisibleError extends ProtocolError {
|
|
|
270
263
|
static error() {
|
|
271
264
|
return 'element not visible';
|
|
272
265
|
}
|
|
273
|
-
|
|
274
266
|
}
|
|
275
267
|
|
|
276
268
|
export class InvalidElementStateError extends ProtocolError {
|
|
@@ -295,7 +287,6 @@ export class InvalidElementStateError extends ProtocolError {
|
|
|
295
287
|
static error() {
|
|
296
288
|
return 'invalid element state';
|
|
297
289
|
}
|
|
298
|
-
|
|
299
290
|
}
|
|
300
291
|
|
|
301
292
|
export class UnknownError extends ProtocolError {
|
|
@@ -318,7 +309,6 @@ export class UnknownError extends ProtocolError {
|
|
|
318
309
|
static error() {
|
|
319
310
|
return 'unknown error';
|
|
320
311
|
}
|
|
321
|
-
|
|
322
312
|
}
|
|
323
313
|
|
|
324
314
|
export class UnknownMethodError extends ProtocolError {
|
|
@@ -342,7 +332,6 @@ export class UnknownMethodError extends ProtocolError {
|
|
|
342
332
|
static error() {
|
|
343
333
|
return 'unknown method';
|
|
344
334
|
}
|
|
345
|
-
|
|
346
335
|
}
|
|
347
336
|
|
|
348
337
|
export class UnsupportedOperationError extends ProtocolError {
|
|
@@ -365,7 +354,6 @@ export class UnsupportedOperationError extends ProtocolError {
|
|
|
365
354
|
static error() {
|
|
366
355
|
return 'unsupported operation';
|
|
367
356
|
}
|
|
368
|
-
|
|
369
357
|
}
|
|
370
358
|
|
|
371
359
|
export class ElementIsNotSelectableError extends ProtocolError {
|
|
@@ -388,7 +376,6 @@ export class ElementIsNotSelectableError extends ProtocolError {
|
|
|
388
376
|
static w3cStatus() {
|
|
389
377
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
390
378
|
}
|
|
391
|
-
|
|
392
379
|
}
|
|
393
380
|
|
|
394
381
|
export class ElementClickInterceptedError extends ProtocolError {
|
|
@@ -413,7 +400,6 @@ export class ElementClickInterceptedError extends ProtocolError {
|
|
|
413
400
|
static w3cStatus() {
|
|
414
401
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
415
402
|
}
|
|
416
|
-
|
|
417
403
|
}
|
|
418
404
|
|
|
419
405
|
export class ElementNotInteractableError extends ProtocolError {
|
|
@@ -437,7 +423,6 @@ export class ElementNotInteractableError extends ProtocolError {
|
|
|
437
423
|
static w3cStatus() {
|
|
438
424
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
439
425
|
}
|
|
440
|
-
|
|
441
426
|
}
|
|
442
427
|
|
|
443
428
|
export class InsecureCertificateError extends ProtocolError {
|
|
@@ -458,7 +443,6 @@ export class InsecureCertificateError extends ProtocolError {
|
|
|
458
443
|
static w3cStatus() {
|
|
459
444
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
460
445
|
}
|
|
461
|
-
|
|
462
446
|
}
|
|
463
447
|
|
|
464
448
|
export class JavaScriptError extends ProtocolError {
|
|
@@ -481,7 +465,6 @@ export class JavaScriptError extends ProtocolError {
|
|
|
481
465
|
static error() {
|
|
482
466
|
return 'javascript error';
|
|
483
467
|
}
|
|
484
|
-
|
|
485
468
|
}
|
|
486
469
|
|
|
487
470
|
export class XPathLookupError extends ProtocolError {
|
|
@@ -504,7 +487,6 @@ export class XPathLookupError extends ProtocolError {
|
|
|
504
487
|
static error() {
|
|
505
488
|
return 'invalid selector';
|
|
506
489
|
}
|
|
507
|
-
|
|
508
490
|
}
|
|
509
491
|
|
|
510
492
|
export class TimeoutError extends ProtocolError {
|
|
@@ -527,7 +509,6 @@ export class TimeoutError extends ProtocolError {
|
|
|
527
509
|
static error() {
|
|
528
510
|
return 'timeout';
|
|
529
511
|
}
|
|
530
|
-
|
|
531
512
|
}
|
|
532
513
|
|
|
533
514
|
export class NoSuchWindowError extends ProtocolError {
|
|
@@ -552,7 +533,6 @@ export class NoSuchWindowError extends ProtocolError {
|
|
|
552
533
|
static w3cStatus() {
|
|
553
534
|
return HTTPStatusCodes.NOT_FOUND;
|
|
554
535
|
}
|
|
555
|
-
|
|
556
536
|
}
|
|
557
537
|
|
|
558
538
|
export class InvalidArgumentError extends ProtocolError {
|
|
@@ -575,7 +555,6 @@ export class InvalidArgumentError extends ProtocolError {
|
|
|
575
555
|
static w3cStatus() {
|
|
576
556
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
577
557
|
}
|
|
578
|
-
|
|
579
558
|
}
|
|
580
559
|
|
|
581
560
|
export class InvalidCookieDomainError extends ProtocolError {
|
|
@@ -600,7 +579,6 @@ export class InvalidCookieDomainError extends ProtocolError {
|
|
|
600
579
|
static w3cStatus() {
|
|
601
580
|
return HTTPStatusCodes.BAD_REQUEST;
|
|
602
581
|
}
|
|
603
|
-
|
|
604
582
|
}
|
|
605
583
|
|
|
606
584
|
export class NoSuchCookieError extends ProtocolError {
|
|
@@ -624,7 +602,6 @@ export class NoSuchCookieError extends ProtocolError {
|
|
|
624
602
|
static error() {
|
|
625
603
|
return 'no such cookie';
|
|
626
604
|
}
|
|
627
|
-
|
|
628
605
|
}
|
|
629
606
|
|
|
630
607
|
export class UnableToSetCookieError extends ProtocolError {
|
|
@@ -647,7 +624,6 @@ export class UnableToSetCookieError extends ProtocolError {
|
|
|
647
624
|
static error() {
|
|
648
625
|
return 'unable to set cookie';
|
|
649
626
|
}
|
|
650
|
-
|
|
651
627
|
}
|
|
652
628
|
|
|
653
629
|
export class UnexpectedAlertOpenError extends ProtocolError {
|
|
@@ -670,7 +646,6 @@ export class UnexpectedAlertOpenError extends ProtocolError {
|
|
|
670
646
|
static error() {
|
|
671
647
|
return 'unexpected alert open';
|
|
672
648
|
}
|
|
673
|
-
|
|
674
649
|
}
|
|
675
650
|
|
|
676
651
|
export class NoAlertOpenError extends ProtocolError {
|
|
@@ -693,7 +668,6 @@ export class NoAlertOpenError extends ProtocolError {
|
|
|
693
668
|
static error() {
|
|
694
669
|
return 'no such alert';
|
|
695
670
|
}
|
|
696
|
-
|
|
697
671
|
}
|
|
698
672
|
|
|
699
673
|
export class NoSuchAlertError extends NoAlertOpenError {}
|
|
@@ -718,7 +692,6 @@ export class ScriptTimeoutError extends ProtocolError {
|
|
|
718
692
|
static error() {
|
|
719
693
|
return 'script timeout';
|
|
720
694
|
}
|
|
721
|
-
|
|
722
695
|
}
|
|
723
696
|
|
|
724
697
|
export class InvalidElementCoordinatesError extends ProtocolError {
|
|
@@ -741,7 +714,6 @@ export class InvalidElementCoordinatesError extends ProtocolError {
|
|
|
741
714
|
static error() {
|
|
742
715
|
return 'invalid coordinates';
|
|
743
716
|
}
|
|
744
|
-
|
|
745
717
|
}
|
|
746
718
|
|
|
747
719
|
export class InvalidCoordinatesError extends InvalidElementCoordinatesError {}
|
|
@@ -766,7 +738,6 @@ export class IMENotAvailableError extends ProtocolError {
|
|
|
766
738
|
static error() {
|
|
767
739
|
return 'unsupported operation';
|
|
768
740
|
}
|
|
769
|
-
|
|
770
741
|
}
|
|
771
742
|
|
|
772
743
|
export class IMEEngineActivationFailedError extends ProtocolError {
|
|
@@ -789,7 +760,6 @@ export class IMEEngineActivationFailedError extends ProtocolError {
|
|
|
789
760
|
static error() {
|
|
790
761
|
return 'unsupported operation';
|
|
791
762
|
}
|
|
792
|
-
|
|
793
763
|
}
|
|
794
764
|
|
|
795
765
|
export class InvalidSelectorError extends ProtocolError {
|
|
@@ -812,13 +782,12 @@ export class InvalidSelectorError extends ProtocolError {
|
|
|
812
782
|
static error() {
|
|
813
783
|
return 'invalid selector';
|
|
814
784
|
}
|
|
815
|
-
|
|
816
785
|
}
|
|
817
786
|
|
|
818
787
|
export class SessionNotCreatedError extends ProtocolError {
|
|
819
788
|
constructor(message: string = '', cause?: Error) {
|
|
820
789
|
super(
|
|
821
|
-
`A new session could not be created.${message ?
|
|
790
|
+
`A new session could not be created.${message ? ' Details: ' + message : ''}`,
|
|
822
791
|
SessionNotCreatedError.code(),
|
|
823
792
|
SessionNotCreatedError.w3cStatus(),
|
|
824
793
|
SessionNotCreatedError.error(),
|
|
@@ -835,7 +804,6 @@ export class SessionNotCreatedError extends ProtocolError {
|
|
|
835
804
|
static error() {
|
|
836
805
|
return 'session not created';
|
|
837
806
|
}
|
|
838
|
-
|
|
839
807
|
}
|
|
840
808
|
|
|
841
809
|
export class MoveTargetOutOfBoundsError extends ProtocolError {
|
|
@@ -858,7 +826,6 @@ export class MoveTargetOutOfBoundsError extends ProtocolError {
|
|
|
858
826
|
static error() {
|
|
859
827
|
return 'move target out of bounds';
|
|
860
828
|
}
|
|
861
|
-
|
|
862
829
|
}
|
|
863
830
|
|
|
864
831
|
export class NoSuchContextError extends ProtocolError {
|
|
@@ -875,7 +842,6 @@ export class NoSuchContextError extends ProtocolError {
|
|
|
875
842
|
static code() {
|
|
876
843
|
return 35;
|
|
877
844
|
}
|
|
878
|
-
|
|
879
845
|
}
|
|
880
846
|
|
|
881
847
|
export class InvalidContextError extends ProtocolError {
|
|
@@ -892,7 +858,6 @@ export class InvalidContextError extends ProtocolError {
|
|
|
892
858
|
static code() {
|
|
893
859
|
return 36;
|
|
894
860
|
}
|
|
895
|
-
|
|
896
861
|
}
|
|
897
862
|
|
|
898
863
|
// Aliases to UnknownMethodError
|
|
@@ -927,7 +892,6 @@ export class UnableToCaptureScreen extends ProtocolError {
|
|
|
927
892
|
static error() {
|
|
928
893
|
return 'unable to capture screen';
|
|
929
894
|
}
|
|
930
|
-
|
|
931
895
|
}
|
|
932
896
|
|
|
933
897
|
// Equivalent to W3C InvalidArgumentError
|
|
@@ -948,22 +912,21 @@ export class ProxyRequestError extends BaseError {
|
|
|
948
912
|
private readonly _w3cErrorStatus?: number;
|
|
949
913
|
private readonly _jwpError?: MJSONWPError;
|
|
950
914
|
|
|
951
|
-
constructor(
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
httpStatus?: number,
|
|
955
|
-
cause?: Error,
|
|
956
|
-
) {
|
|
957
|
-
const [responseErrorObj, originalMessage] = ProxyRequestError._parseHttpResponse(httpResponseData);
|
|
915
|
+
constructor(message: string, httpResponseData: any, httpStatus?: number, cause?: Error) {
|
|
916
|
+
const [responseErrorObj, originalMessage] =
|
|
917
|
+
ProxyRequestError._parseHttpResponse(httpResponseData);
|
|
958
918
|
super(
|
|
959
919
|
util.isEmpty(message)
|
|
960
|
-
? `Proxy request unsuccessful.${originalMessage ?
|
|
920
|
+
? `Proxy request unsuccessful.${originalMessage ? ' ' + originalMessage : ''}`
|
|
961
921
|
: message,
|
|
962
922
|
cause,
|
|
963
923
|
);
|
|
964
924
|
|
|
965
925
|
// If the response error is an object and value is an object, it's a W3C error (for JSONWP value is a string)
|
|
966
|
-
if (
|
|
926
|
+
if (
|
|
927
|
+
util.isPlainObject(responseErrorObj.value) &&
|
|
928
|
+
Object.hasOwn(responseErrorObj.value, 'error')
|
|
929
|
+
) {
|
|
967
930
|
this._w3cError = responseErrorObj.value as unknown as typeof this._w3cError;
|
|
968
931
|
this._w3cErrorStatus = httpStatus;
|
|
969
932
|
} else if (Object.hasOwn(responseErrorObj, 'status')) {
|
|
@@ -990,7 +953,11 @@ export class ProxyRequestError extends BaseError {
|
|
|
990
953
|
// If it's MJSONWP error, returns actual error cause for request failure based on `jsonwp.status`
|
|
991
954
|
return errorFromMJSONWPStatusCode(this._jwpError.status, this._jwpError.value);
|
|
992
955
|
}
|
|
993
|
-
if (
|
|
956
|
+
if (
|
|
957
|
+
util.hasValue(this._w3cError) &&
|
|
958
|
+
typeof this._w3cErrorStatus === 'number' &&
|
|
959
|
+
this._w3cErrorStatus >= 300
|
|
960
|
+
) {
|
|
994
961
|
return errorFromW3CJsonCode(
|
|
995
962
|
this._w3cError.error,
|
|
996
963
|
this._w3cError.message || this.message,
|
|
@@ -1003,9 +970,9 @@ export class ProxyRequestError extends BaseError {
|
|
|
1003
970
|
|
|
1004
971
|
function generateBadParametersMessage(
|
|
1005
972
|
paramRequirements: ParameterRequirements,
|
|
1006
|
-
paramNames: string[]
|
|
973
|
+
paramNames: string[],
|
|
1007
974
|
): string {
|
|
1008
|
-
const toArray = function <T>
|
|
975
|
+
const toArray = function <T>(x: T | T[]): T[] {
|
|
1009
976
|
if (x === undefined) {
|
|
1010
977
|
return [];
|
|
1011
978
|
}
|
|
@@ -1017,7 +984,9 @@ function generateBadParametersMessage(
|
|
|
1017
984
|
|
|
1018
985
|
const requiredParamNames = toArray(paramRequirements.required);
|
|
1019
986
|
const actualParamNames = toArray(paramNames);
|
|
1020
|
-
const missingRequiredParamNames = requiredParamNames.filter(
|
|
987
|
+
const missingRequiredParamNames = requiredParamNames.filter(
|
|
988
|
+
(name) => !actualParamNames.includes(name),
|
|
989
|
+
);
|
|
1021
990
|
const resultLines: string[] = [];
|
|
1022
991
|
resultLines.push(
|
|
1023
992
|
util.isEmpty(missingRequiredParamNames)
|
|
@@ -1031,7 +1000,7 @@ function generateBadParametersMessage(
|
|
|
1031
1000
|
resultLines.push(`Known required parameters are: ${JSON.stringify(requiredParamNames)}`);
|
|
1032
1001
|
}
|
|
1033
1002
|
const optionalParamNames = toArray(paramRequirements.optional).filter(
|
|
1034
|
-
(name): name is string => typeof name === 'string' && !['sessionId', 'id'].includes(name)
|
|
1003
|
+
(name): name is string => typeof name === 'string' && !['sessionId', 'id'].includes(name),
|
|
1035
1004
|
);
|
|
1036
1005
|
if (!util.isEmpty(optionalParamNames)) {
|
|
1037
1006
|
resultLines.push(`Known optional parameters are: ${JSON.stringify(optionalParamNames)}`);
|
|
@@ -1088,22 +1057,25 @@ export const errors = {
|
|
|
1088
1057
|
ProxyRequestError,
|
|
1089
1058
|
} as const;
|
|
1090
1059
|
|
|
1091
|
-
const jsonwpErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors)
|
|
1092
|
-
|
|
1060
|
+
const jsonwpErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors).reduce(
|
|
1061
|
+
(acc: Record<string, Class<ProtocolError>>, ErrorClass: any) => {
|
|
1093
1062
|
if ('code' in ErrorClass) {
|
|
1094
1063
|
acc[ErrorClass.code()] = ErrorClass;
|
|
1095
1064
|
}
|
|
1096
1065
|
return acc;
|
|
1097
|
-
},
|
|
1066
|
+
},
|
|
1067
|
+
{},
|
|
1068
|
+
);
|
|
1098
1069
|
|
|
1099
|
-
const w3cErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors)
|
|
1100
|
-
|
|
1070
|
+
const w3cErrorCodeMap: Record<string, Class<ProtocolError>> = Object.values(errors).reduce(
|
|
1071
|
+
(acc: Record<string, Class<ProtocolError>>, ErrorClass: any) => {
|
|
1101
1072
|
if ('error' in ErrorClass) {
|
|
1102
1073
|
acc[ErrorClass.error()] = ErrorClass;
|
|
1103
1074
|
}
|
|
1104
1075
|
return acc;
|
|
1105
|
-
},
|
|
1106
|
-
|
|
1076
|
+
},
|
|
1077
|
+
{},
|
|
1078
|
+
);
|
|
1107
1079
|
|
|
1108
1080
|
interface MJSONWPError {
|
|
1109
1081
|
status: number;
|
|
@@ -1135,7 +1107,10 @@ export function isErrorType<T>(err: any, type: Class<T>): err is T {
|
|
|
1135
1107
|
* @param value The error message, or an object with a `message` property
|
|
1136
1108
|
* @return The error that is associated with provided JSONWP status code
|
|
1137
1109
|
*/
|
|
1138
|
-
export function errorFromMJSONWPStatusCode(
|
|
1110
|
+
export function errorFromMJSONWPStatusCode(
|
|
1111
|
+
code: number,
|
|
1112
|
+
value: string | {message: string} = '',
|
|
1113
|
+
): ProtocolError {
|
|
1139
1114
|
const ErrorClass = jsonwpErrorCodeMap[code] ?? UnknownError;
|
|
1140
1115
|
mjsonwpLog.debug(`Matched JSONWP error code ${code} to ${ErrorClass.name}`);
|
|
1141
1116
|
// if `value` is an object, pull message from it, otherwise use the plain
|
|
@@ -1151,7 +1126,11 @@ export function errorFromMJSONWPStatusCode(code: number, value: string | {messag
|
|
|
1151
1126
|
* @param stacktrace an optional error stacktrace
|
|
1152
1127
|
* @return The error that is associated with the W3C error string
|
|
1153
1128
|
*/
|
|
1154
|
-
export function errorFromW3CJsonCode(
|
|
1129
|
+
export function errorFromW3CJsonCode(
|
|
1130
|
+
signature: string,
|
|
1131
|
+
message: string,
|
|
1132
|
+
stacktrace?: string,
|
|
1133
|
+
): ProtocolError {
|
|
1155
1134
|
const ErrorClass = w3cErrorCodeMap[signature.toLowerCase()] ?? UnknownError;
|
|
1156
1135
|
w3cLog.debug(`Matched W3C error code '${signature}' to ${ErrorClass.name}`);
|
|
1157
1136
|
const resultError = new ErrorClass(message);
|
|
@@ -1164,17 +1143,18 @@ export function errorFromW3CJsonCode(signature: string, message: string, stacktr
|
|
|
1164
1143
|
*
|
|
1165
1144
|
* @param err The error that needs to be translated
|
|
1166
1145
|
*/
|
|
1167
|
-
export function getResponseForW3CError(err: any): [number, {
|
|
1168
|
-
const protocolErrorToResponse: (e: ProtocolError) => [number, {
|
|
1169
|
-
|
|
1146
|
+
export function getResponseForW3CError(err: any): [number, {value: W3CError}] {
|
|
1147
|
+
const protocolErrorToResponse: (e: ProtocolError) => [number, {value: W3CError}] = (
|
|
1148
|
+
e: ProtocolError,
|
|
1149
|
+
) => [
|
|
1170
1150
|
e.w3cStatus,
|
|
1171
1151
|
{
|
|
1172
1152
|
value: {
|
|
1173
1153
|
error: e.error,
|
|
1174
1154
|
message: e.message,
|
|
1175
1155
|
stacktrace: e.stacktrace || e.stack,
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1156
|
+
},
|
|
1157
|
+
},
|
|
1178
1158
|
];
|
|
1179
1159
|
|
|
1180
1160
|
// err is ProtocolError
|