appium-remote-debugger 14.0.5 → 15.0.0

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.
@@ -27,25 +27,6 @@ const COMMANDS = /** @type {const} */ ({
27
27
  });
28
28
 
29
29
  export class RemoteMessages {
30
- constructor (isTargetBased = true) {
31
- this._isTargetBased = isTargetBased;
32
- }
33
-
34
- /**
35
- * @param {boolean} isTargetBased
36
- * @returns {boolean}
37
- */
38
- set isTargetBased (isTargetBased) {
39
- this._isTargetBased = isTargetBased;
40
- }
41
-
42
- /**
43
- * @returns {boolean}
44
- */
45
- get isTargetBased () {
46
- return this._isTargetBased;
47
- }
48
-
49
30
  // #region Connection functions
50
31
 
51
32
  /**
@@ -158,34 +139,22 @@ export class RemoteMessages {
158
139
  * JavaScript).
159
140
  */
160
141
 
161
- let realMethod;
162
- let realParams;
163
- if (this.isTargetBased) {
164
- realMethod = 'Target.sendMessageToTarget';
165
- realParams = {
166
- targetId,
167
- message: JSON.stringify({
168
- id,
169
- method,
170
- params: Object.assign({
171
- objectGroup: OBJECT_GROUP,
172
- includeCommandLineAPI: true,
173
- doNotPauseOnExceptionsAndMuteConsole: false,
174
- emulateUserGesture: false,
175
- generatePreview: false,
176
- saveResult: false,
177
- }, params)
178
- }),
179
- };
180
- } else {
181
- realMethod = method;
182
- realParams = Object.assign({
183
- objectGroup: OBJECT_GROUP,
184
- includeCommandLineAPI: true,
185
- doNotPauseOnExceptionsAndMuteConsole: false,
186
- emulateUserGesture: false,
187
- }, params);
188
- }
142
+ const realMethod = 'Target.sendMessageToTarget';
143
+ const realParams = {
144
+ targetId,
145
+ message: JSON.stringify({
146
+ id,
147
+ method,
148
+ params: Object.assign({
149
+ objectGroup: OBJECT_GROUP,
150
+ includeCommandLineAPI: true,
151
+ doNotPauseOnExceptionsAndMuteConsole: false,
152
+ emulateUserGesture: false,
153
+ generatePreview: false,
154
+ saveResult: false,
155
+ }, params)
156
+ }),
157
+ };
189
158
 
190
159
  const plist = {
191
160
  __argument: {
@@ -212,19 +181,15 @@ export class RemoteMessages {
212
181
  getMinimalCommand (opts) {
213
182
  const {method, params, connId, senderId, appIdKey, pageIdKey, targetId, id} = opts;
214
183
 
215
- let realMethod = method;
216
- let realParams = params;
217
- if (this.isTargetBased) {
218
- realMethod = 'Target.sendMessageToTarget';
219
- realParams = {
220
- targetId,
221
- message: JSON.stringify({
222
- id,
223
- method,
224
- params,
225
- }),
226
- };
227
- }
184
+ const realMethod = 'Target.sendMessageToTarget';
185
+ const realParams = {
186
+ targetId,
187
+ message: JSON.stringify({
188
+ id,
189
+ method,
190
+ params,
191
+ }),
192
+ };
228
193
 
229
194
  const plist = {
230
195
  __argument: {
@@ -14,9 +14,6 @@ const MIN_WAIT_FOR_TARGET_TIMEOUT_MS = 30000;
14
14
  // although we still should not allow it to take forever
15
15
  const PAGE_INIT_TIMEOUT_MS = 10 * 60 * 1000; // 10 minutes
16
16
  const WAIT_FOR_TARGET_INTERVAL_MS = 100;
17
- const MIN_PLATFORM_FOR_TARGET_BASED = '12.2';
18
- // `Target.exists` protocol method was removed from WebKit in 13.4
19
- const MIN_PLATFORM_NO_TARGET_EXISTS = '13.4';
20
17
  const NO_TARGET_SUPPORTED_ERROR = `'target' domain was not found`;
21
18
  const MISSING_TARGET_ERROR_PATTERN = /Missing target/i;
22
19
  const NO_TARGET_PRESENT_YET_ERRORS = [
@@ -27,20 +24,6 @@ const NO_TARGET_PRESENT_YET_ERRORS = [
27
24
  export const NEW_APP_CONNECTED_ERROR = 'New application has connected';
28
25
  export const EMPTY_PAGE_DICTIONARY_ERROR = 'Empty page dictionary received';
29
26
 
30
- /**
31
- * @param {boolean} isSafari
32
- * @param {string} platformVersion
33
- * @returns {boolean}
34
- */
35
- function isTargetBased (isSafari, platformVersion) {
36
- // On iOS 12.2 the messages get sent through the Target domain
37
- // On iOS 13.0+, WKWebView also needs to follow the Target domain,
38
- // so here only check the target OS version as the default behaviour.
39
- const isHighVersion = util.compareVersions(platformVersion, '>=', MIN_PLATFORM_FOR_TARGET_BASED);
40
- log.debug(`Checking which communication style to use (${isSafari ? '' : 'non-'}Safari on platform version '${platformVersion}')`);
41
- log.debug(`Platform version equal or higher than '${MIN_PLATFORM_FOR_TARGET_BASED}': ${isHighVersion}`);
42
- return isHighVersion;
43
- }
44
27
 
45
28
  export class RpcClient {
46
29
  /** @type {RpcMessageHandler|undefined} */
@@ -146,8 +129,15 @@ export class RpcClient {
146
129
  this._targetSubscriptions = new EventEmitter();
147
130
  this._provisionedPages = new Set();
148
131
 
149
- // start with a best guess for the protocol
150
- this.isTargetBased = platformVersion ? isTargetBased(isSafari, platformVersion) : true;
132
+ this.remoteMessages = new RemoteMessages();
133
+
134
+ this.messageHandler = new RpcMessageHandler();
135
+ // add handlers for internal events
136
+ this.messageHandler.on('Target.targetCreated', this.addTarget.bind(this));
137
+ this.messageHandler.on('Target.didCommitProvisionalTarget', this.updateTarget.bind(this));
138
+ this.messageHandler.on('Target.targetDestroyed', this.removeTarget.bind(this));
139
+ this.messageHandler.on('Runtime.executionContextCreated', this.onExecutionContextCreated.bind(this));
140
+ this.messageHandler.on('Heap.garbageCollected', this.onGarbageCollected.bind(this));
151
141
  }
152
142
 
153
143
  /**
@@ -157,13 +147,6 @@ export class RpcClient {
157
147
  return this._contexts;
158
148
  }
159
149
 
160
- /**
161
- * @returns {boolean}
162
- */
163
- get needsTarget () {
164
- return this.isTargetBased;
165
- }
166
-
167
150
  /**
168
151
  * @returns {AppToTargetsMap}
169
152
  */
@@ -227,40 +210,6 @@ export class RpcClient {
227
210
  return this;
228
211
  }
229
212
 
230
- /**
231
- * @param {boolean} isTargetBased
232
- */
233
- set isTargetBased (isTargetBased) {
234
- log.warn(`Setting communication protocol: using ${isTargetBased ? 'Target-based' : 'full Web Inspector protocol'} communication`);
235
- this._isTargetBased = isTargetBased;
236
-
237
- if (!this.remoteMessages) {
238
- this.remoteMessages = new RemoteMessages(isTargetBased);
239
- } else {
240
- this.remoteMessages.isTargetBased = isTargetBased;
241
- }
242
-
243
- if (!this.messageHandler) {
244
- this.messageHandler = new RpcMessageHandler(isTargetBased);
245
-
246
- // add handlers for internal events
247
- this.messageHandler.on('Target.targetCreated', this.addTarget.bind(this));
248
- this.messageHandler.on('Target.didCommitProvisionalTarget', this.updateTarget.bind(this));
249
- this.messageHandler.on('Target.targetDestroyed', this.removeTarget.bind(this));
250
- this.messageHandler.on('Runtime.executionContextCreated', this.onExecutionContextCreated.bind(this));
251
- this.messageHandler.on('Heap.garbageCollected', this.onGarbageCollected.bind(this));
252
- } else {
253
- this.messageHandler.isTargetBased = isTargetBased;
254
- }
255
- }
256
-
257
- /**
258
- * @returns {boolean}
259
- */
260
- get isTargetBased () {
261
- return !!this._isTargetBased;
262
- }
263
-
264
213
  /**
265
214
  *
266
215
  * @param {import('../types').AppIdKey} appIdKey
@@ -268,10 +217,6 @@ export class RpcClient {
268
217
  * @returns {Promise<import('../types').TargetId | undefined>}
269
218
  */
270
219
  async waitForTarget (appIdKey, pageIdKey) {
271
- if (!this.needsTarget) {
272
- log.debug(`Target-based communication is not needed, skipping wait for target`);
273
- return;
274
- }
275
220
  let target = this.getTarget(appIdKey, pageIdKey);
276
221
  if (target) {
277
222
  log.debug(
@@ -323,14 +268,8 @@ export class RpcClient {
323
268
  } = opts;
324
269
  const messageLc = (err.message || '').toLowerCase();
325
270
  if (messageLc.includes(NO_TARGET_SUPPORTED_ERROR)) {
326
- log.info(
327
- 'The target device does not support Target based communication. ' +
328
- 'Will follow non-target based communication.'
329
- );
330
- this.isTargetBased = false;
331
271
  return await this.sendToDevice(command, opts, waitForResponse);
332
272
  } else if (appIdKey && NO_TARGET_PRESENT_YET_ERRORS.some((error) => messageLc.includes(error))) {
333
- this.isTargetBased = true;
334
273
  await this.waitForTarget(appIdKey, /** @type {import('../types').PageIdKey} */ (pageIdKey));
335
274
  return await this.sendToDevice(command, opts, waitForResponse);
336
275
  }
@@ -356,18 +295,15 @@ export class RpcClient {
356
295
 
357
296
  // keep track of the messages coming and going using a simple sequential id
358
297
  const msgId = this.msgId++;
359
- let wrapperMsgId = msgId;
360
- if (this.isTargetBased) {
361
- // for target-base communication, everything is wrapped up
362
- wrapperMsgId = this.msgId++;
363
- // acknowledge wrapper message
364
- // @ts-ignore messageHandler must be defined
365
- this.messageHandler.on(wrapperMsgId.toString(), function (err) {
366
- if (err) {
367
- reject(err);
368
- }
369
- });
370
- }
298
+ // for target-base communication, everything is wrapped up
299
+ const wrapperMsgId = this.msgId++;
300
+ // acknowledge wrapper message
301
+ // @ts-ignore messageHandler must be defined
302
+ this.messageHandler.on(wrapperMsgId.toString(), function (err) {
303
+ if (err) {
304
+ reject(err);
305
+ }
306
+ });
371
307
 
372
308
  const appIdKey = opts.appIdKey;
373
309
  const pageIdKey = opts.pageIdKey;
@@ -456,7 +392,7 @@ export class RpcClient {
456
392
  const msg = `Sending '${cmd.__selector}' message` +
457
393
  (appIdKey ? ` to app '${appIdKey}'` : '') +
458
394
  (pageIdKey ? `, page '${pageIdKey}'` : '') +
459
- (this.needsTarget && targetId ? `, target '${targetId}'` : '') +
395
+ (targetId ? `, target '${targetId}'` : '') +
460
396
  ` (id: ${msgId}): '${command}'`;
461
397
  log.debug(msg);
462
398
  try {
@@ -721,15 +657,6 @@ export class RpcClient {
721
657
  await this.send('setSenderKey', sendOpts);
722
658
  log.debug('Sender key set');
723
659
 
724
- if (!this.isTargetBased) {
725
- await this._initializePage(appIdKey, pageIdKey);
726
- return;
727
- }
728
-
729
- if (this.isTargetBased && util.compareVersions(this.platformVersion, '<', MIN_PLATFORM_NO_TARGET_EXISTS)) {
730
- await this.send('Target.exists', sendOpts, false);
731
- }
732
-
733
660
  await this.waitForTarget(appIdKey, pageIdKey);
734
661
  await this.waitForPageInitialization(appIdKey, pageIdKey);
735
662
  }
@@ -5,27 +5,8 @@ import EventEmitters from 'events';
5
5
 
6
6
 
7
7
  export default class RpcMessageHandler extends EventEmitters {
8
- constructor (isTargetBased = true) {
8
+ constructor () {
9
9
  super();
10
- this._isTargetBased = isTargetBased;
11
- }
12
-
13
- /**
14
- * Get whether the message handler is target-based or not.
15
- * @return {boolean}
16
- */
17
- get isTargetBased () {
18
- return this._isTargetBased;
19
- }
20
-
21
- /**
22
- * Set whether the message handler is target-based or not.
23
- *
24
- * @param {boolean} isTargetBased
25
- * @returns {void}
26
- */
27
- set isTargetBased (isTargetBased) {
28
- this._isTargetBased = !!isTargetBased;
29
10
  }
30
11
 
31
12
  /**
@@ -225,7 +206,7 @@ export default class RpcMessageHandler extends EventEmitters {
225
206
  return;
226
207
  }
227
208
  case 'Target.dispatchMessageFromTarget': {
228
- if (!dataKey.error && this.isTargetBased) {
209
+ if (!dataKey.error) {
229
210
  try {
230
211
  const message = JSON.parse(dataKey.params.message);
231
212
  msgId = _.isUndefined(message.id) ? '' : String(message.id);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "appium"
6
6
  ],
7
- "version": "14.0.5",
7
+ "version": "15.0.0",
8
8
  "author": "Appium Contributors",
9
9
  "license": "Apache-2.0",
10
10
  "repository": {