appium-remote-debugger 12.2.6 → 12.2.7

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.
@@ -32,35 +32,35 @@ export class RemoteDebugger extends EventEmitter {
32
32
  protected _skippedApps: string[];
33
33
  protected _clientEventListeners: StringRecord<EventListener[]>;
34
34
  protected _appDict: AppDict;
35
- protected _appIdKey: AppIdKey | null | undefined;
36
- protected _pageIdKey: PageIdKey | null | undefined;
37
- protected _connectedDrivers: StringRecord[] | undefined;
38
- protected _currentState: string | undefined;
39
- protected _pageLoadDelay: B<void> | undefined;
35
+ protected _appIdKey?: AppIdKey;
36
+ protected _pageIdKey?: PageIdKey;
37
+ protected _connectedDrivers?: StringRecord[];
38
+ protected _currentState?: string;
39
+ protected _pageLoadDelay?: B<void>;
40
40
  protected _rpcClient: RpcClient | null;
41
41
  protected _pageLoading: boolean;
42
42
  protected _navigatingToPage: boolean;
43
43
  protected _allowNavigationWithoutReload: boolean;
44
- protected _pageLoadMs: number | undefined;
45
- protected readonly _pageLoadStrategy: string | undefined;
44
+ protected _pageLoadMs?: number;
45
+ protected readonly _pageLoadStrategy?: string;
46
46
  protected readonly _log: AppiumLogger;
47
- protected readonly _bundleId: string | undefined;
48
- protected readonly _additionalBundleIds: string[] | undefined;
49
- protected readonly _platformVersion: string | undefined;
47
+ protected readonly _bundleId?: string;
48
+ protected readonly _additionalBundleIds?: string[];
49
+ protected readonly _platformVersion?: string;
50
50
  protected readonly _isSafari: boolean;
51
51
  protected readonly _includeSafari: boolean;
52
52
  protected readonly _useNewSafari: boolean;
53
53
  protected readonly _garbageCollectOnExecute: boolean;
54
- protected readonly _host: string | undefined;
55
- protected readonly _port: number | undefined;
56
- protected readonly _socketPath: string | undefined;
57
- protected readonly _remoteDebugProxy: any | undefined;
54
+ protected readonly _host?: string;
55
+ protected readonly _port?: number;
56
+ protected readonly _socketPath?: string;
57
+ protected readonly _remoteDebugProxy?: any;
58
58
  protected readonly _pageReadyTimeout: number;
59
59
  protected readonly _logAllCommunication: boolean;
60
60
  protected readonly _logAllCommunicationHexDump: boolean;
61
- protected readonly _socketChunkSize: number | undefined;
62
- protected readonly _webInspectorMaxFrameLength: number | undefined;
63
- protected readonly _fullPageInitialization: boolean | undefined;
61
+ protected readonly _socketChunkSize?: number;
62
+ protected readonly _webInspectorMaxFrameLength?: number;
63
+ protected readonly _fullPageInitialization?: boolean;
64
64
 
65
65
  // events
66
66
  static readonly EVENT_PAGE_CHANGE: string;
@@ -187,8 +187,8 @@ export class RemoteDebugger extends EventEmitter {
187
187
  setup (): void {
188
188
  // app handling configuration
189
189
  this._appDict = {};
190
- this._appIdKey = null;
191
- this._pageIdKey = null;
190
+ this._appIdKey = undefined;
191
+ this._pageIdKey = undefined;
192
192
  this._pageLoading = false;
193
193
  this._navigatingToPage = false;
194
194
  this._currentState = undefined;
@@ -203,8 +203,8 @@ export class RemoteDebugger extends EventEmitter {
203
203
  this.log.debug('Cleaning up listeners');
204
204
 
205
205
  this._appDict = {};
206
- this._appIdKey = null;
207
- this._pageIdKey = null;
206
+ this._appIdKey = undefined;
207
+ this._pageIdKey = undefined;
208
208
  this._pageLoading = false;
209
209
 
210
210
  this._rpcClient = null;
@@ -81,7 +81,7 @@ export class RemoteMessages {
81
81
  * @param {string} connId
82
82
  * @param {string} senderId
83
83
  * @param {import('../types').AppIdKey} appIdKey
84
- * @param {import('../types').PageIdKey} pageIdKey
84
+ * @param {import('../types').PageIdKey} [pageIdKey]
85
85
  * @returns {import('../types').RemoteCommand}
86
86
  */
87
87
  setSenderKey (connId, senderId, appIdKey, pageIdKey) {
@@ -101,8 +101,8 @@ export class RemoteMessages {
101
101
  *
102
102
  * @param {string} connId
103
103
  * @param {import('../types').AppIdKey} appIdKey
104
- * @param {import('../types').PageIdKey} pageIdKey
105
- * @param {boolean} enabled
104
+ * @param {import('../types').PageIdKey} [pageIdKey]
105
+ * @param {boolean} [enabled]
106
106
  * @returns {import('../types').RemoteCommand}
107
107
  */
108
108
  indicateWebView (connId, appIdKey, pageIdKey, enabled) {
@@ -291,18 +291,18 @@ export class RemoteMessages {
291
291
  }
292
292
  return this.setConnectionKey(connId);
293
293
  case 'indicateWebView':
294
- if (!connId) {
295
- throw new Error('Cannot indicate web view without a connection ID');
294
+ if (!connId || !appIdKey) {
295
+ throw new Error('Cannot indicate web view without a connection ID and app ID');
296
296
  }
297
297
  return this.indicateWebView(connId, appIdKey, pageIdKey, !!opts.enabled);
298
298
  case 'connectToApp':
299
- if (!connId) {
300
- throw new Error('Cannot connect to app without a connection ID');
299
+ if (!connId || !appIdKey) {
300
+ throw new Error('Cannot connect to app without a connection ID and app ID');
301
301
  }
302
302
  return this.connectToApp(connId, appIdKey);
303
303
  case 'setSenderKey':
304
- if (!connId || !senderId) {
305
- throw new Error('Cannot set sender key without a connection ID and sender ID');
304
+ if (!connId || !senderId || !appIdKey) {
305
+ throw new Error('Cannot set sender key without a connection ID, sender ID, and app ID');
306
306
  }
307
307
  return this.setSenderKey(connId, senderId, appIdKey, pageIdKey);
308
308
  case 'launchApplication':
@@ -315,7 +315,7 @@ export class RemoteMessages {
315
315
  // deal with WebKit commands
316
316
  const builderFunction = COMMANDS[command] || MINIMAL_COMMAND;
317
317
  return this[builderFunction]({
318
- ...getProtocolCommand(id, command, opts),
318
+ ...getProtocolCommand(/** @type {string} */ (id), command, opts),
319
319
  connId,
320
320
  appIdKey,
321
321
  senderId,
@@ -298,11 +298,11 @@ export class RpcClient {
298
298
  /**
299
299
  *
300
300
  * @param {string} command
301
- * @param {Record<string, any>} [opts]
301
+ * @param {import('../types').RemoteCommandOpts} opts
302
302
  * @param {boolean} [waitForResponse]
303
303
  * @returns {Promise<any>}
304
304
  */
305
- async send (command, opts = {}, waitForResponse = true) {
305
+ async send (command, opts, waitForResponse = true) {
306
306
  const timer = new timing.Timer().start();
307
307
  const {
308
308
  appIdKey,
@@ -319,9 +319,9 @@ export class RpcClient {
319
319
  );
320
320
  this.isTargetBased = false;
321
321
  return await this.sendToDevice(command, opts, waitForResponse);
322
- } else if (NO_TARGET_PRESENT_YET_ERRORS.some((error) => messageLc.includes(error))) {
322
+ } else if (appIdKey && NO_TARGET_PRESENT_YET_ERRORS.some((error) => messageLc.includes(error))) {
323
323
  this.isTargetBased = true;
324
- await this.waitForTarget(appIdKey, pageIdKey);
324
+ await this.waitForTarget(appIdKey, /** @type {import('../types').PageIdKey} */ (pageIdKey));
325
325
  return await this.sendToDevice(command, opts, waitForResponse);
326
326
  }
327
327
  throw err;
@@ -333,11 +333,11 @@ export class RpcClient {
333
333
  /**
334
334
  *
335
335
  * @param {string} command
336
- * @param {Record<string, any>} opts
336
+ * @param {import('../types').RemoteCommandOpts} opts
337
337
  * @param {boolean} [waitForResponse]
338
338
  * @returns {Promise<any>}
339
339
  */
340
- async sendToDevice (command, opts = {}, waitForResponse = true) {
340
+ async sendToDevice (command, opts, waitForResponse = true) {
341
341
  return await new B(async (resolve, reject) => {
342
342
  // promise to be resolved whenever remote debugger
343
343
  // replies to our request
@@ -548,11 +548,10 @@ export class RpcClient {
548
548
  targets[page] = newTargetId;
549
549
  const opts = {appIdKey: app, pageIdKey: parseInt(page, 10)};
550
550
  (async () => {
551
- try {
552
- // This is needed to enable the broadcast of page lifecycle events
553
- await this.sendToDevice('Page.enable', opts, true);
554
- } catch (err) {
555
- log.warn(err.message);
551
+ if (this.fullPageInitialization) {
552
+ await this.initializePageFull(opts.appIdKey, opts.pageIdKey);
553
+ } else {
554
+ await this.initializePage(opts.appIdKey, opts.pageIdKey);
556
555
  }
557
556
  this._targetSubscriptions.emit(ON_TARGET_PROVISIONED_EVENT, {
558
557
  ...opts,
@@ -579,11 +578,14 @@ export class RpcClient {
579
578
  }
580
579
 
581
580
  /**
582
- * @param {import('../types').AppIdKey} appIdKey
583
- * @param {import('../types').PageIdKey} pageIdKey
584
- * @returns {any}
581
+ * @param {import('../types').AppIdKey} [appIdKey]
582
+ * @param {import('../types').PageIdKey} [pageIdKey]
583
+ * @returns {string | undefined}
585
584
  */
586
585
  getTarget (appIdKey, pageIdKey) {
586
+ if (!appIdKey || !pageIdKey) {
587
+ return;
588
+ }
587
589
  return (this.targets[appIdKey] || {})[pageIdKey];
588
590
  }
589
591
 
@@ -641,17 +643,25 @@ export class RpcClient {
641
643
  pageIdKey,
642
644
  };
643
645
 
644
- await this.send('Inspector.enable', sendOpts, false);
645
- await this.send('Page.enable', sendOpts, false);
646
+ // The sequence of domains is important
647
+ for (const domain of [
648
+ 'Inspector.enable',
649
+ 'Page.enable',
650
+ 'Runtime.enable',
646
651
 
647
- // go through the tasks to initialize
648
- await this.send('Network.enable', sendOpts, false);
649
- await this.send('Runtime.enable', sendOpts, false);
650
- await this.send('Heap.enable', sendOpts, false);
651
- await this.send('Debugger.enable', sendOpts, false);
652
- await this.send('Console.enable', sendOpts, false);
652
+ 'Network.enable',
653
+ 'Heap.enable',
654
+ 'Debugger.enable',
655
+ 'Console.enable',
653
656
 
654
- await this.send('Inspector.initialized', sendOpts);
657
+ 'Inspector.initialized',
658
+ ]) {
659
+ try {
660
+ await this.send(domain, sendOpts);
661
+ } catch (err) {
662
+ log.info(`Cannot enable domain '${domain}' during initialization: ${err.message}`);
663
+ }
664
+ }
655
665
  }
656
666
 
657
667
  /**
@@ -668,61 +678,84 @@ export class RpcClient {
668
678
  pageIdKey,
669
679
  };
670
680
 
671
- await this.send('Inspector.enable', sendOpts, false);
672
- await this.send('Page.enable', sendOpts, false);
673
-
674
- // go through the tasks to initialize
675
- await this.send('Page.getResourceTree', sendOpts, false);
676
- await this.send('Network.enable', sendOpts, false);
677
- await this.send('Network.setResourceCachingDisabled', Object.assign({
678
- disabled: false,
679
- }, sendOpts), false);
680
- await this.send('DOMStorage.enable', sendOpts, false);
681
- await this.send('Database.enable', sendOpts, false);
682
- await this.send('IndexedDB.enable', sendOpts, false);
683
- await this.send('CSS.enable', sendOpts, false);
684
- await this.send('Runtime.enable', sendOpts, false);
685
- await this.send('Heap.enable', sendOpts, false);
686
- await this.send('Memory.enable', sendOpts, false);
687
- await this.send('ApplicationCache.enable', sendOpts, false);
688
- await this.send('ApplicationCache.getFramesWithManifests', sendOpts, false);
689
- await this.send('Timeline.setInstruments', Object.assign({
690
- instruments: ['Timeline', 'ScriptProfiler', 'CPU'],
691
- }, sendOpts), false);
692
- await this.send('Timeline.setAutoCaptureEnabled', Object.assign({
693
- enabled: false,
694
- }, sendOpts), false);
695
- await this.send('Debugger.enable', sendOpts, false);
696
- await this.send('Debugger.setBreakpointsActive', Object.assign({
697
- active: true,
698
- }, sendOpts), false);
699
- await this.send('Debugger.setPauseOnExceptions', Object.assign({
700
- state: 'none',
701
- }, sendOpts), false);
702
- await this.send('Debugger.setPauseOnAssertions', Object.assign({
703
- enabled: false,
704
- }, sendOpts), false);
705
- await this.send('Debugger.setAsyncStackTraceDepth', Object.assign({
706
- depth: 200,
707
- }, sendOpts), false);
708
- await this.send('Debugger.setPauseForInternalScripts', Object.assign({
709
- shouldPause: false,
710
- }, sendOpts), false);
711
-
712
- await this.send('LayerTree.enable', sendOpts, false);
713
- await this.send('Worker.enable', sendOpts, false);
714
- await this.send('Canvas.enable', sendOpts, false);
715
- await this.send('Console.enable', sendOpts, false);
716
- await this.send('DOM.getDocument', sendOpts, false);
717
- const loggingChannels = await this.send('Console.getLoggingChannels', sendOpts);
718
- for (const source of (loggingChannels.channels || []).map((entry) => entry.source)) {
719
- await this.send('Console.setLoggingChannelLevel', Object.assign({
720
- source,
721
- level: 'verbose',
722
- }, sendOpts), false);
723
- }
681
+ // The sequence of commands here is important
682
+ const domainsToOptsMap = {
683
+ 'Inspector.enable': sendOpts,
684
+ 'Page.enable': sendOpts,
685
+ 'Runtime.enable': sendOpts,
686
+
687
+ 'Page.getResourceTree': sendOpts,
688
+ 'Network.enable': sendOpts,
689
+ 'Network.setResourceCachingDisabled': {
690
+ disabled: false,
691
+ ...sendOpts,
692
+ },
693
+ 'DOMStorage.enable': sendOpts,
694
+ 'Database.enable': sendOpts,
695
+ 'IndexedDB.enable': sendOpts,
696
+ 'CSS.enable': sendOpts,
697
+ 'Heap.enable': sendOpts,
698
+ 'Memory.enable': sendOpts,
699
+ 'ApplicationCache.enable': sendOpts,
700
+ 'ApplicationCache.getFramesWithManifests': sendOpts,
701
+ 'Timeline.setInstruments': {
702
+ instruments: ['Timeline', 'ScriptProfiler', 'CPU'],
703
+ ...sendOpts,
704
+ },
705
+ 'Timeline.setAutoCaptureEnabled': {
706
+ enabled: false,
707
+ ...sendOpts,
708
+ },
709
+ 'Debugger.enable': sendOpts,
710
+ 'Debugger.setBreakpointsActive': {
711
+ active: true,
712
+ ...sendOpts,
713
+ },
714
+ 'Debugger.setPauseOnExceptions': {
715
+ state: 'none',
716
+ ...sendOpts,
717
+ },
718
+ 'Debugger.setPauseOnAssertions': {
719
+ enabled: false,
720
+ ...sendOpts,
721
+ },
722
+ 'Debugger.setAsyncStackTraceDepth': {
723
+ depth: 200,
724
+ ...sendOpts,
725
+ },
726
+ 'Debugger.setPauseForInternalScripts': {
727
+ shouldPause: false,
728
+ ...sendOpts,
729
+ },
730
+ 'LayerTree.enable': sendOpts,
731
+ 'Worker.enable': sendOpts,
732
+ 'Canvas.enable': sendOpts,
733
+ 'Console.enable': sendOpts,
734
+ 'DOM.getDocument': sendOpts,
735
+ 'Console.getLoggingChannels': sendOpts,
736
+
737
+ 'Inspector.initialized': sendOpts,
738
+ };
724
739
 
725
- await this.send('Inspector.initialized', sendOpts);
740
+ for (const [domain, opts] of Object.entries(domainsToOptsMap)) {
741
+ try {
742
+ const res = await this.send(domain, opts);
743
+ if (domain === 'Console.getLoggingChannels') {
744
+ for (const source of (res?.channels || []).map((/** @type {{ source: any; }} */ entry) => entry.source)) {
745
+ try {
746
+ await this.send('Console.setLoggingChannelLevel', Object.assign({
747
+ source,
748
+ level: 'verbose',
749
+ }, sendOpts));
750
+ } catch (err) {
751
+ log.info(`Cannot set logging channel level for '${source}': ${err.message}`);
752
+ }
753
+ }
754
+ }
755
+ } catch (err) {
756
+ log.info(`Cannot enable domain '${domain}' during full initialization: ${err.message}`);
757
+ }
758
+ }
726
759
  }
727
760
 
728
761
  /**
package/lib/types.ts CHANGED
@@ -85,14 +85,15 @@ export type AppIdKey = string | number;
85
85
  export type PageIdKey = string | number;
86
86
 
87
87
  export interface RemoteCommandOpts {
88
- appIdKey: AppIdKey;
89
- pageIdKey: PageIdKey;
90
- id: string;
88
+ appIdKey?: AppIdKey;
89
+ pageIdKey?: PageIdKey;
90
+ id?: string;
91
91
  connId?: string;
92
92
  senderId?: string;
93
93
  targetId?: string;
94
94
  bundleId?: string;
95
95
  enabled?: boolean;
96
+ [key: string]: any;
96
97
  }
97
98
 
98
99
  export interface ProtocolCommandOpts {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "keywords": [
5
5
  "appium"
6
6
  ],
7
- "version": "12.2.6",
7
+ "version": "12.2.7",
8
8
  "author": "Appium Contributors",
9
9
  "license": "Apache-2.0",
10
10
  "repository": {