appium-remote-debugger 11.5.2 → 11.5.4

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.
@@ -3,13 +3,19 @@ import RpcClient from './rpc-client';
3
3
  import { services } from 'appium-ios-device';
4
4
 
5
5
 
6
- export default class RpcClientRealDevice extends RpcClient {
6
+ export class RpcClientRealDevice extends RpcClient {
7
+ /**
8
+ * @param {import('./rpc-client').RpcClientOptions} [opts={}]
9
+ */
7
10
  constructor (opts = {}) {
8
11
  super(Object.assign({
9
12
  shouldCheckForTarget: false,
10
13
  }, opts));
11
14
  }
12
15
 
16
+ /**
17
+ * @override
18
+ */
13
19
  async connect () {
14
20
  this.service = await services.startWebInspectorService(this.udid, {
15
21
  osVersion: this.platformVersion,
@@ -24,6 +30,9 @@ export default class RpcClientRealDevice extends RpcClient {
24
30
  this.isConnected = true;
25
31
  }
26
32
 
33
+ /**
34
+ * @override
35
+ */
27
36
  async disconnect () {
28
37
  if (!this.isConnected) {
29
38
  return;
@@ -35,10 +44,16 @@ export default class RpcClientRealDevice extends RpcClient {
35
44
  this.isConnected = false;
36
45
  }
37
46
 
47
+ /**
48
+ * @override
49
+ */
38
50
  async sendMessage (cmd) { // eslint-disable-line require-await
39
51
  this.service.sendMessage(cmd);
40
52
  }
41
53
 
54
+ /**
55
+ * @override
56
+ */
42
57
  async receive (data) {
43
58
  if (!this.isConnected) {
44
59
  return;
@@ -47,3 +62,5 @@ export default class RpcClientRealDevice extends RpcClient {
47
62
  await this.messageHandler.handleMessage(data);
48
63
  }
49
64
  }
65
+
66
+ export default RpcClientRealDevice;
@@ -5,8 +5,25 @@ import net from 'net';
5
5
  import RpcClient from './rpc-client';
6
6
  import { services } from 'appium-ios-device';
7
7
 
8
+ export class RpcClientSimulator extends RpcClient {
9
+ /** @type {string|undefined} */
10
+ host;
8
11
 
9
- export default class RpcClientSimulator extends RpcClient {
12
+ /** @type {number|undefined} */
13
+ port;
14
+
15
+ /** @type {any} */
16
+ messageProxy;
17
+
18
+ /** @type {import('node:net').Socket|null} */
19
+ socket;
20
+
21
+ /** @type {string|undefined} */
22
+ socketPath;
23
+
24
+ /**
25
+ * @param {import('./rpc-client').RpcClientOptions & RpcClientSimulatorOptions} [opts={}]
26
+ */
10
27
  constructor (opts = {}) {
11
28
  super(Object.assign({
12
29
  shouldCheckForTarget: false,
@@ -28,6 +45,9 @@ export default class RpcClientSimulator extends RpcClient {
28
45
  this.socketPath = socketPath;
29
46
  }
30
47
 
48
+ /**
49
+ * @override
50
+ */
31
51
  async connect () {
32
52
  // create socket and handle its messages
33
53
  if (this.socketPath) {
@@ -59,7 +79,7 @@ export default class RpcClientSimulator extends RpcClient {
59
79
  // tcp socket
60
80
  log.debug(`Connecting to remote debugger ${this.messageProxy ? 'via proxy ' : ''}through TCP: ${this.host}:${this.port}`);
61
81
  this.socket = new net.Socket();
62
- this.socket.connect(this.port, this.host);
82
+ this.socket.connect(/** @type {number} */ (this.port), /** @type {String} */ (this.host));
63
83
  }
64
84
 
65
85
  this.socket.setNoDelay(true);
@@ -107,6 +127,9 @@ export default class RpcClientSimulator extends RpcClient {
107
127
  });
108
128
  }
109
129
 
130
+ /**
131
+ * @override
132
+ */
110
133
  async disconnect () {
111
134
  if (!this.isConnected) {
112
135
  return;
@@ -118,6 +141,9 @@ export default class RpcClientSimulator extends RpcClient {
118
141
  this.isConnected = false;
119
142
  }
120
143
 
144
+ /**
145
+ * @override
146
+ */
121
147
  async sendMessage (cmd) {
122
148
  let onSocketError;
123
149
 
@@ -148,6 +174,9 @@ export default class RpcClientSimulator extends RpcClient {
148
174
  });
149
175
  }
150
176
 
177
+ /**
178
+ * @override
179
+ */
151
180
  async receive (data) {
152
181
  if (!this.isConnected) {
153
182
  return;
@@ -166,3 +195,13 @@ export default class RpcClientSimulator extends RpcClient {
166
195
  await this.messageHandler.handleMessage(data);
167
196
  }
168
197
  }
198
+
199
+ export default RpcClientSimulator;
200
+
201
+ /**
202
+ * @typedef {Object} RpcClientSimulatorOptions
203
+ * @property {string} [socketPath]
204
+ * @property {string} [host='::1']
205
+ * @property {number} [port]
206
+ * @property {any} [messageProxy]
207
+ */
@@ -8,17 +8,18 @@ import { util, timing } from '@appium/support';
8
8
  import { EventEmitter } from 'node:events';
9
9
  import { ON_TARGET_PROVISIONED_EVENT } from './constants';
10
10
 
11
-
12
11
  const DATA_LOG_LENGTH = {length: 200};
13
-
14
- const WAIT_FOR_TARGET_TIMEOUT = 10000;
15
- const WAIT_FOR_TARGET_INTERVAL = 1000;
16
-
12
+ const WAIT_FOR_TARGET_TIMEOUT_MS = 10000;
13
+ const WAIT_FOR_TARGET_INTERVAL_MS = 1000;
17
14
  const MIN_PLATFORM_FOR_TARGET_BASED = '12.2';
18
-
19
15
  // `Target.exists` protocol method was removed from WebKit in 13.4
20
16
  const MIN_PLATFORM_NO_TARGET_EXISTS = '13.4';
21
17
 
18
+ /**
19
+ * @param {boolean} isSafari
20
+ * @param {string} platformVersion
21
+ * @returns {boolean}
22
+ */
22
23
  function isTargetBased (isSafari, platformVersion) {
23
24
  // On iOS 12.2 the messages get sent through the Target domain
24
25
  // On iOS 13.0+, WKWebView also needs to follow the Target domain,
@@ -39,13 +40,62 @@ export class RpcClient {
39
40
  /** @type {boolean} */
40
41
  connected;
41
42
 
42
- constructor (opts = {}) {
43
- this._targets = [];
44
- this._shouldCheckForTarget = !!opts.shouldCheckForTarget;
43
+ /** @type {boolean} */
44
+ isSafari;
45
+
46
+ /** @type {string} */
47
+ connId;
48
+
49
+ /** @type {string} */
50
+ senderId;
51
+
52
+ /** @type {number} */
53
+ msgId;
54
+
55
+ /** @type {string|undefined} */
56
+ udid;
57
+
58
+ /** @type {boolean|undefined} */
59
+ logAllCommunication;
60
+
61
+ /** @type {boolean|undefined} */
62
+ logAllCommunicationHexDump;
63
+
64
+ /** @type {number|undefined} */
65
+ socketChunkSize;
66
+
67
+ /** @type {number|undefined} */
68
+ webInspectorMaxFrameLength;
69
+
70
+ /** @type {boolean|undefined} */
71
+ fullPageInitialization;
72
+
73
+ /** @type {string|undefined} */
74
+ bundleId;
45
75
 
76
+ /** @type {string} */
77
+ platformVersion;
78
+
79
+ /** @type {string[]} */
80
+ _contexts;
81
+
82
+ /** @type {import('@appium/types').StringRecord} */
83
+ _targets;
84
+
85
+ /** @type {EventEmitter} */
86
+ _targetSubscriptions;
87
+
88
+ /** @type {boolean} */
89
+ _shouldCheckForTarget;
90
+
91
+ /**
92
+ *
93
+ * @param {RpcClientOptions} [opts={}]
94
+ */
95
+ constructor (opts = {}) {
46
96
  const {
47
97
  bundleId,
48
- platformVersion = {},
98
+ platformVersion = '',
49
99
  isSafari = true,
50
100
  logAllCommunication = false,
51
101
  logAllCommunicationHexDump = false,
@@ -79,21 +129,34 @@ export class RpcClient {
79
129
  this._targetSubscriptions = new EventEmitter();
80
130
 
81
131
  // start with a best guess for the protocol
82
- this.isTargetBased = isTargetBased(isSafari, this.platformVersion);
132
+ this._shouldCheckForTarget = !!opts.shouldCheckForTarget;
133
+ this.isTargetBased = platformVersion ? isTargetBased(isSafari, platformVersion) : true;
83
134
  }
84
135
 
136
+ /**
137
+ * @returns {string[]}
138
+ */
85
139
  get contexts () {
86
140
  return this._contexts;
87
141
  }
88
142
 
143
+ /**
144
+ * @returns {boolean}
145
+ */
89
146
  get needsTarget () {
90
147
  return this.shouldCheckForTarget && this.isTargetBased;
91
148
  }
92
149
 
150
+ /**
151
+ * @returns {import('@appium/types').StringRecord}
152
+ */
93
153
  get targets () {
94
154
  return this._targets;
95
155
  }
96
156
 
157
+ /**
158
+ * @returns {boolean}
159
+ */
97
160
  get shouldCheckForTarget () {
98
161
  return this._shouldCheckForTarget;
99
162
  }
@@ -102,36 +165,65 @@ export class RpcClient {
102
165
  this._shouldCheckForTarget = !!shouldCheckForTarget;
103
166
  }
104
167
 
168
+ /**
169
+ * @returns {boolean}
170
+ */
105
171
  get isConnected () {
106
172
  return this.connected;
107
173
  }
108
174
 
175
+ /**
176
+ * @param {boolean} connected
177
+ */
109
178
  set isConnected (connected) {
110
179
  this.connected = !!connected;
111
180
  }
112
181
 
182
+ /**
183
+ * @returns {EventEmitter}
184
+ */
113
185
  get targetSubscriptions() {
114
186
  return this._targetSubscriptions;
115
187
  }
116
188
 
189
+ /**
190
+ *
191
+ * @param {string} event
192
+ * @param {Function} listener
193
+ * @returns {this}
194
+ */
117
195
  on (event, listener) {
118
196
  // @ts-ignore messageHandler must be defined here
119
197
  this.messageHandler.on(event, listener);
120
198
  return this;
121
199
  }
122
200
 
201
+ /**
202
+ *
203
+ * @param {string} event
204
+ * @param {Function} listener
205
+ * @returns {this}
206
+ */
123
207
  once (event, listener) {
124
208
  // @ts-ignore messageHandler must be defined here
125
209
  this.messageHandler.once(event, listener);
126
210
  return this;
127
211
  }
128
212
 
213
+ /**
214
+ * @param {string} event
215
+ * @param {Function} listener
216
+ * @returns {this}
217
+ */
129
218
  off (event, listener) {
130
219
  // @ts-ignore messageHandler must be defined here
131
220
  this.messageHandler.off(event, listener);
132
221
  return this;
133
222
  }
134
223
 
224
+ /**
225
+ * @param {boolean} isTargetBased
226
+ */
135
227
  set isTargetBased (isTargetBased) {
136
228
  log.warn(`Setting communication protocol: using ${isTargetBased ? 'Target-based' : 'full Web Inspector protocol'} communication`);
137
229
  this._isTargetBased = isTargetBased;
@@ -156,8 +248,11 @@ export class RpcClient {
156
248
  }
157
249
  }
158
250
 
251
+ /**
252
+ * @returns {boolean}
253
+ */
159
254
  get isTargetBased () {
160
- return this._isTargetBased;
255
+ return !!this._isTargetBased;
161
256
  }
162
257
 
163
258
  /**
@@ -179,8 +274,8 @@ export class RpcClient {
179
274
  // otherwise waiting is necessary to see what the target is
180
275
  try {
181
276
  await waitForCondition(() => !_.isEmpty(this.getTarget(appIdKey, pageIdKey)), {
182
- waitMs: WAIT_FOR_TARGET_TIMEOUT,
183
- intervalMs: WAIT_FOR_TARGET_INTERVAL,
277
+ waitMs: WAIT_FOR_TARGET_TIMEOUT_MS,
278
+ intervalMs: WAIT_FOR_TARGET_INTERVAL_MS,
184
279
  error: 'No targets found, unable to communicate with device',
185
280
  });
186
281
  } catch (err) {
@@ -348,12 +443,21 @@ export class RpcClient {
348
443
  this.messageHandler?.removeAllListeners();
349
444
  }
350
445
 
446
+ /**
447
+ * @param {string} command
448
+ * @returns {Promise<void>}
449
+ */
351
450
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
352
451
  async sendMessage (command) { // eslint-disable-line require-await
353
452
  throw new Error(`Sub-classes need to implement a 'sendMessage' function`);
354
453
  }
355
454
 
356
- async receive (/* data */) { // eslint-disable-line require-await
455
+ /**
456
+ * @param {any} data
457
+ * @returns {Promise<void>}
458
+ */
459
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
460
+ async receive (data) { // eslint-disable-line require-await
357
461
  throw new Error(`Sub-classes need to implement a 'receive' function`);
358
462
  }
359
463
 
@@ -681,6 +785,9 @@ export class RpcClient {
681
785
  this.contexts.push(context.id);
682
786
  }
683
787
 
788
+ /**
789
+ * @returns {void}
790
+ */
684
791
  onGarbageCollected () {
685
792
  // just want to log that this is happening, as it can affect opertion
686
793
  log.debug(`Web Inspector garbage collected`);
@@ -698,3 +805,17 @@ export class RpcClient {
698
805
  }
699
806
 
700
807
  export default RpcClient;
808
+
809
+ /**
810
+ * @typedef {Object} RpcClientOptions
811
+ * @property {string} [bundleId]
812
+ * @property {string} [platformVersion='']
813
+ * @property {boolean} [isSafari=true]
814
+ * @property {boolean} [logAllCommunication=false]
815
+ * @property {boolean} [logAllCommunicationHexDump=false]
816
+ * @property {number} [webInspectorMaxFrameLength]
817
+ * @property {number} [socketChunkSize]
818
+ * @property {boolean} [fullPageInitialization=false]
819
+ * @property {string} [udid]
820
+ * @property {boolean} [shouldCheckForTarget]
821
+ */
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "appium"
6
6
  ],
7
- "version": "11.5.2",
7
+ "version": "11.5.4",
8
8
  "author": "Appium Contributors",
9
9
  "license": "Apache-2.0",
10
10
  "repository": {