appium-remote-debugger 11.5.9 → 12.0.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/build/lib/mixins/connect.d.ts +2 -45
  3. package/build/lib/mixins/connect.d.ts.map +1 -1
  4. package/build/lib/mixins/connect.js +46 -46
  5. package/build/lib/mixins/connect.js.map +1 -1
  6. package/build/lib/mixins/cookies.d.ts.map +1 -1
  7. package/build/lib/mixins/cookies.js +8 -7
  8. package/build/lib/mixins/cookies.js.map +1 -1
  9. package/build/lib/mixins/events.d.ts +27 -5
  10. package/build/lib/mixins/events.d.ts.map +1 -1
  11. package/build/lib/mixins/events.js +47 -6
  12. package/build/lib/mixins/events.js.map +1 -1
  13. package/build/lib/mixins/execute.d.ts.map +1 -1
  14. package/build/lib/mixins/execute.js +16 -12
  15. package/build/lib/mixins/execute.js.map +1 -1
  16. package/build/lib/mixins/message-handlers.d.ts +0 -31
  17. package/build/lib/mixins/message-handlers.d.ts.map +1 -1
  18. package/build/lib/mixins/message-handlers.js +21 -22
  19. package/build/lib/mixins/message-handlers.js.map +1 -1
  20. package/build/lib/mixins/misc.d.ts +2 -24
  21. package/build/lib/mixins/misc.d.ts.map +1 -1
  22. package/build/lib/mixins/misc.js +15 -51
  23. package/build/lib/mixins/misc.js.map +1 -1
  24. package/build/lib/mixins/navigate.d.ts +1 -25
  25. package/build/lib/mixins/navigate.d.ts.map +1 -1
  26. package/build/lib/mixins/navigate.js +36 -30
  27. package/build/lib/mixins/navigate.js.map +1 -1
  28. package/build/lib/mixins/property-accessors.d.ts +27 -0
  29. package/build/lib/mixins/property-accessors.d.ts.map +1 -0
  30. package/build/lib/mixins/property-accessors.js +95 -0
  31. package/build/lib/mixins/property-accessors.js.map +1 -0
  32. package/build/lib/mixins/screenshot.d.ts.map +1 -1
  33. package/build/lib/mixins/screenshot.js +3 -2
  34. package/build/lib/mixins/screenshot.js.map +1 -1
  35. package/build/lib/remote-debugger-real-device.d.ts +7 -19
  36. package/build/lib/remote-debugger-real-device.d.ts.map +1 -1
  37. package/build/lib/remote-debugger-real-device.js +12 -20
  38. package/build/lib/remote-debugger-real-device.js.map +1 -1
  39. package/build/lib/remote-debugger.d.ts +63 -167
  40. package/build/lib/remote-debugger.d.ts.map +1 -1
  41. package/build/lib/remote-debugger.js +75 -119
  42. package/build/lib/remote-debugger.js.map +1 -1
  43. package/build/lib/types.d.ts +41 -1
  44. package/build/lib/types.d.ts.map +1 -1
  45. package/build/tsconfig.tsbuildinfo +1 -1
  46. package/lib/mixins/connect.js +66 -52
  47. package/lib/mixins/cookies.js +11 -7
  48. package/lib/mixins/events.js +50 -6
  49. package/lib/mixins/execute.js +27 -14
  50. package/lib/mixins/message-handlers.js +30 -23
  51. package/lib/mixins/misc.js +18 -51
  52. package/lib/mixins/navigate.js +44 -30
  53. package/lib/mixins/property-accessors.ts +96 -0
  54. package/lib/mixins/screenshot.js +7 -2
  55. package/lib/remote-debugger-real-device.ts +28 -0
  56. package/lib/remote-debugger.ts +268 -0
  57. package/lib/types.ts +44 -1
  58. package/package.json +1 -1
  59. package/lib/remote-debugger-real-device.js +0 -39
  60. package/lib/remote-debugger.js +0 -299
@@ -7,6 +7,17 @@ import events from './events';
7
7
  import { timing, util } from '@appium/support';
8
8
  import { retryInterval, waitForCondition } from 'asyncbox';
9
9
  import _ from 'lodash';
10
+ import {
11
+ setAppIdKey,
12
+ getAppDict,
13
+ getAppIdKey,
14
+ setPageIdKey,
15
+ getRcpClient,
16
+ getIsSafari,
17
+ getIncludeSafari,
18
+ getBundleId,
19
+ getAdditionalBundleIds,
20
+ } from './property-accessors';
10
21
 
11
22
  const APP_CONNECT_TIMEOUT_MS = 0;
12
23
  const APP_CONNECT_INTERVAL_MS = 100;
@@ -36,7 +47,7 @@ export async function setConnectionKey () {
36
47
  *
37
48
  * @this {RemoteDebugger}
38
49
  * @param {number} [timeout=APP_CONNECT_TIMEOUT_MS]
39
- * @returns {Promise<import('@appium/types').StringRecord>}
50
+ * @returns {Promise<import('../types').AppDict>}
40
51
  */
41
52
  export async function connect (timeout = APP_CONNECT_TIMEOUT_MS) {
42
53
  this.setup();
@@ -66,19 +77,19 @@ export async function connect (timeout = APP_CONNECT_TIMEOUT_MS) {
66
77
  const timer = new timing.Timer().start();
67
78
  this.log.debug(`Waiting up to ${timeout}ms for applications to be reported`);
68
79
  try {
69
- await waitForCondition(() => !_.isEmpty(this.appDict), {
80
+ await waitForCondition(() => !_.isEmpty(getAppDict(this)), {
70
81
  waitMs: timeout,
71
82
  intervalMs: APP_CONNECT_INTERVAL_MS,
72
83
  });
73
84
  this.log.debug(
74
- `Retrieved ${util.pluralize('application', _.size(this.appDict), true)} ` +
85
+ `Retrieved ${util.pluralize('application', _.size(getAppDict(this)), true)} ` +
75
86
  `within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`
76
87
  );
77
88
  } catch (err) {
78
89
  this.log.debug(`Timed out waiting for applications to be reported`);
79
90
  }
80
91
  }
81
- return this.appDict || {};
92
+ return _.cloneDeep(getAppDict(this));
82
93
  } catch (err) {
83
94
  this.log.error(`Error setting connection key: ${err.message}`);
84
95
  await this.disconnect();
@@ -92,9 +103,7 @@ export async function connect (timeout = APP_CONNECT_TIMEOUT_MS) {
92
103
  * @returns {Promise<void>}
93
104
  */
94
105
  export async function disconnect () {
95
- if (this.rpcClient) {
96
- await this.rpcClient.disconnect();
97
- }
106
+ await getRcpClient(this)?.disconnect();
98
107
  this.emit(events.EVENT_DISCONNECT, true);
99
108
  this.teardown();
100
109
  }
@@ -115,23 +124,23 @@ export async function selectApp (currentUrl = null, maxTries = SELECT_APP_RETRIE
115
124
  rpcClient.shouldCheckForTarget = false;
116
125
  try {
117
126
  const timer = new timing.Timer().start();
118
- if (!this.appDict || _.isEmpty(this.appDict)) {
127
+ if (_.isEmpty(getAppDict(this))) {
119
128
  this.log.debug('No applications currently connected.');
120
129
  return [];
121
130
  }
122
131
 
123
- const { appIdKey } = await this.searchForApp(currentUrl, maxTries, ignoreAboutBlankUrl);
124
- if (this.appIdKey !== appIdKey) {
125
- this.log.debug(`Received altered app id, updating from '${this.appIdKey}' to '${appIdKey}'`);
126
- this.appIdKey = appIdKey;
132
+ const { appIdKey } = await searchForApp.bind(this)(currentUrl, maxTries, ignoreAboutBlankUrl);
133
+ if (getAppIdKey(this) !== appIdKey) {
134
+ this.log.debug(`Received altered app id, updating from '${getAppIdKey(this)}' to '${appIdKey}'`);
135
+ setAppIdKey(this, appIdKey);
127
136
  }
128
137
  logApplicationDictionary.bind(this)();
129
138
  // translate the dictionary into a useful form, and return to sender
130
- this.log.debug(`Finally selecting app ${this.appIdKey}`);
139
+ this.log.debug(`Finally selecting app ${getAppIdKey(this)}`);
131
140
 
132
141
  /** @type {import('../types').Page[]} */
133
142
  const fullPageArray = [];
134
- for (const [app, info] of _.toPairs(this.appDict)) {
143
+ for (const [app, info] of _.toPairs(getAppDict(this))) {
135
144
  if (!_.isArray(info.pageArray) || !info.isActive) {
136
145
  continue;
137
146
  }
@@ -153,6 +162,32 @@ export async function selectApp (currentUrl = null, maxTries = SELECT_APP_RETRIE
153
162
  }
154
163
  }
155
164
 
165
+ /**
166
+ *
167
+ * @this {RemoteDebugger}
168
+ * @param {string|number} appIdKey
169
+ * @param {string|number} pageIdKey
170
+ * @param {boolean} [skipReadyCheck]
171
+ * @returns {Promise<void>}
172
+ */
173
+ export async function selectPage (appIdKey, pageIdKey, skipReadyCheck = false) {
174
+ const fullAppIdKey = _.startsWith(`${appIdKey}`, 'PID:') ? `${appIdKey}` : `PID:${appIdKey}`;
175
+ setAppIdKey(this, fullAppIdKey);
176
+ setPageIdKey(this, pageIdKey);
177
+
178
+ this.log.debug(`Selecting page '${pageIdKey}' on app '${fullAppIdKey}' and forwarding socket setup`);
179
+
180
+ const timer = new timing.Timer().start();
181
+
182
+ await this.requireRpcClient().selectPage(fullAppIdKey, pageIdKey);
183
+
184
+ if (!skipReadyCheck && !await this.checkPageIsReady()) {
185
+ await this.waitForDom();
186
+ }
187
+
188
+ this.log.debug(`Selected page after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
189
+ }
190
+
156
191
  /**
157
192
  *
158
193
  * @this {RemoteDebugger}
@@ -161,10 +196,15 @@ export async function selectApp (currentUrl = null, maxTries = SELECT_APP_RETRIE
161
196
  * @param {boolean} ignoreAboutBlankUrl
162
197
  * @returns {Promise<import('../types').AppPage>}
163
198
  */
164
- export async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
165
- const bundleIds = this.includeSafari && !this.isSafari
166
- ? [this.bundleId, ...this.additionalBundleIds, SAFARI_BUNDLE_ID]
167
- : [this.bundleId, ...this.additionalBundleIds];
199
+ async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
200
+ /** @type {string[]} */
201
+ const bundleIds = _.compact(
202
+ [
203
+ getBundleId(this),
204
+ ...(getAdditionalBundleIds(this) ?? []),
205
+ ...(getIncludeSafari(this) && !getIsSafari(this) ? [SAFARI_BUNDLE_ID] : []),
206
+ ]
207
+ );
168
208
  let retryCount = 0;
169
209
  return /** @type {import('../types').AppPage} */ (await retryInterval(maxTries, SELECT_APP_RETRY_SLEEP_MS, async () => {
170
210
  logApplicationDictionary.bind(this)();
@@ -172,7 +212,7 @@ export async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
172
212
  this.log.debug(`Trying out the possible app ids: ${possibleAppIds.join(', ')} (try #${retryCount + 1} of ${maxTries})`);
173
213
  for (const attemptedAppIdKey of possibleAppIds) {
174
214
  try {
175
- if (!this.appDict[attemptedAppIdKey].isActive) {
215
+ if (!getAppDict(this)[attemptedAppIdKey].isActive) {
176
216
  this.log.debug(`Skipping app '${attemptedAppIdKey}' because it is not active`);
177
217
  continue;
178
218
  }
@@ -190,12 +230,12 @@ export async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
190
230
  }
191
231
 
192
232
  // save the page array for this app
193
- this.appDict[appIdKey].pageArray = pageArrayFromDict(pageDict);
233
+ getAppDict(this)[appIdKey].pageArray = pageArrayFromDict(pageDict);
194
234
 
195
235
  // if we are looking for a particular url, make sure we
196
236
  // have the right page. Ignore empty or undefined urls.
197
237
  // Ignore about:blank if requested.
198
- const result = this.searchForPage(this.appDict, currentUrl, ignoreAboutBlankUrl);
238
+ const result = searchForPage.bind(this)(getAppDict(this), currentUrl, ignoreAboutBlankUrl);
199
239
  if (result) {
200
240
  return result;
201
241
  }
@@ -225,7 +265,7 @@ export async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
225
265
  * @param {boolean} [ignoreAboutBlankUrl]
226
266
  * @returns {import('../types').AppPage?}
227
267
  */
228
- export function searchForPage (appsDict, currentUrl = null, ignoreAboutBlankUrl = false) {
268
+ function searchForPage (appsDict, currentUrl = null, ignoreAboutBlankUrl = false) {
229
269
  for (const appDict of _.values(appsDict)) {
230
270
  if (!appDict || !appDict.isActive || !appDict.pageArray || _.isEmpty(appDict.pageArray)) {
231
271
  continue;
@@ -244,39 +284,13 @@ export function searchForPage (appsDict, currentUrl = null, ignoreAboutBlankUrl
244
284
  return null;
245
285
  }
246
286
 
247
- /**
248
- *
249
- * @this {RemoteDebugger}
250
- * @param {string|number} appIdKey
251
- * @param {string|number} pageIdKey
252
- * @param {boolean} [skipReadyCheck]
253
- * @returns {Promise<void>}
254
- */
255
- export async function selectPage (appIdKey, pageIdKey, skipReadyCheck = false) {
256
- this.appIdKey = _.startsWith(`${appIdKey}`, 'PID:') ? `${appIdKey}` : `PID:${appIdKey}`;
257
- this.pageIdKey = pageIdKey;
258
-
259
- this.log.debug(`Selecting page '${pageIdKey}' on app '${this.appIdKey}' and forwarding socket setup`);
260
-
261
- const timer = new timing.Timer().start();
262
-
263
- await this.requireRpcClient().selectPage(this.appIdKey, pageIdKey);
264
-
265
- // make sure everything is ready to go
266
- if (!skipReadyCheck && !await this.checkPageIsReady()) {
267
- await this.waitForDom();
268
- }
269
-
270
- this.log.debug(`Selected page after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
271
- }
272
-
273
287
  /**
274
288
  * @this {RemoteDebugger}
275
289
  * @returns {void}
276
290
  */
277
291
  function logApplicationDictionary () {
278
292
  this.log.debug('Current applications available:');
279
- for (const [app, info] of _.toPairs(this.appDict)) {
293
+ for (const [app, info] of _.toPairs(getAppDict(this))) {
280
294
  this.log.debug(` Application: "${app}"`);
281
295
  for (const [key, value] of _.toPairs(info)) {
282
296
  if (key === 'pageArray' && Array.isArray(value) && value.length) {
@@ -307,7 +321,7 @@ function logApplicationDictionary () {
307
321
  export function getPossibleDebuggerAppKeys(bundleIds) {
308
322
  if (bundleIds.includes(WILDCARD_BUNDLE_ID)) {
309
323
  this.log.debug('Skip checking bundle identifiers because the bundleIds includes a wildcard');
310
- return _.uniq(Object.keys(this.appDict));
324
+ return _.uniq(Object.keys(getAppDict(this)));
311
325
  }
312
326
 
313
327
  // go through the possible bundle identifiers
@@ -324,10 +338,10 @@ export function getPossibleDebuggerAppKeys(bundleIds) {
324
338
  const proxiedAppIds = new Set();
325
339
  for (const bundleId of possibleBundleIds) {
326
340
  // now we need to determine if we should pick a proxy for this instead
327
- for (const appId of appIdsForBundle(bundleId, this.appDict)) {
341
+ for (const appId of appIdsForBundle(bundleId, getAppDict(this))) {
328
342
  proxiedAppIds.add(appId);
329
343
  this.log.debug(`Found app id key '${appId}' for bundle '${bundleId}'`);
330
- for (const [key, data] of _.toPairs(this.appDict)) {
344
+ for (const [key, data] of _.toPairs(getAppDict(this))) {
331
345
  if (data.isProxy && data.hostId === appId) {
332
346
  this.log.debug(
333
347
  `Found separate bundleId '${data.bundleId}' ` +
@@ -1,3 +1,7 @@
1
+ import {
2
+ getAppIdKey,
3
+ getPageIdKey,
4
+ } from './property-accessors';
1
5
 
2
6
  /**
3
7
  *
@@ -7,8 +11,8 @@
7
11
  export async function getCookies () {
8
12
  this.log.debug('Getting cookies');
9
13
  return await this.requireRpcClient().send('Page.getCookies', {
10
- appIdKey: this.appIdKey,
11
- pageIdKey: this.pageIdKey
14
+ appIdKey: getAppIdKey(this),
15
+ pageIdKey: getPageIdKey(this),
12
16
  });
13
17
  }
14
18
 
@@ -21,9 +25,9 @@ export async function getCookies () {
21
25
  export async function setCookie (cookie) {
22
26
  this.log.debug('Setting cookie');
23
27
  return await this.requireRpcClient().send('Page.setCookie', {
24
- appIdKey: this.appIdKey,
25
- pageIdKey: this.pageIdKey,
26
- cookie
28
+ appIdKey: getAppIdKey(this),
29
+ pageIdKey: getPageIdKey(this),
30
+ cookie,
27
31
  });
28
32
  }
29
33
 
@@ -37,8 +41,8 @@ export async function setCookie (cookie) {
37
41
  export async function deleteCookie (cookieName, url) {
38
42
  this.log.debug(`Deleting cookie '${cookieName}' on '${url}'`);
39
43
  return await this.requireRpcClient().send('Page.deleteCookie', {
40
- appIdKey: this.appIdKey,
41
- pageIdKey: this.pageIdKey,
44
+ appIdKey: getAppIdKey(this),
45
+ pageIdKey: getPageIdKey(this),
42
46
  cookieName,
43
47
  url,
44
48
  });
@@ -1,21 +1,25 @@
1
+ import {
2
+ getClientEventListeners,
3
+ } from './property-accessors';
4
+
1
5
  // event emitted publically
2
- export const events = {
6
+ export const events = /** @type {const} */ ({
3
7
  EVENT_PAGE_CHANGE: 'remote_debugger_page_change',
4
8
  EVENT_FRAMES_DETACHED: 'remote_debugger_frames_detached',
5
9
  EVENT_DISCONNECT: 'remote_debugger_disconnect',
6
- };
10
+ });
7
11
 
8
12
  /**
9
13
  * Keep track of the client event listeners so they can be removed
10
14
  *
11
15
  * @this {RemoteDebugger}
12
16
  * @param {string} eventName
13
- * @param {(event: import('@appium/types').StringRecord) => any} listener
17
+ * @param {import('../types').EventListener} listener
14
18
  * @returns {void}
15
19
  */
16
20
  export function addClientEventListener (eventName, listener) {
17
- this._clientEventListeners[eventName] ??= [];
18
- this._clientEventListeners[eventName].push(listener);
21
+ getClientEventListeners(this)[eventName] ??= [];
22
+ getClientEventListeners(this)[eventName].push(listener);
19
23
  this.requireRpcClient().on(eventName, listener);
20
24
  }
21
25
 
@@ -25,11 +29,51 @@ export function addClientEventListener (eventName, listener) {
25
29
  * @returns {void}
26
30
  */
27
31
  export function removeClientEventListener (eventName) {
28
- for (const listener of (this._clientEventListeners[eventName] || [])) {
32
+ for (const listener of (getClientEventListeners(this)[eventName] || [])) {
29
33
  this.requireRpcClient().off(eventName, listener);
30
34
  }
31
35
  }
32
36
 
37
+ /**
38
+ * @this {RemoteDebugger}
39
+ * @param {import('../types').EventListener} listener
40
+ * @returns {void}
41
+ */
42
+ export function startConsole (listener) {
43
+ this.log.debug('Starting to listen for JavaScript console');
44
+ this.addClientEventListener('Console.messageAdded', listener);
45
+ this.addClientEventListener('Console.messageRepeatCountUpdated', listener);
46
+ }
47
+
48
+ /**
49
+ * @this {RemoteDebugger}
50
+ * @returns {void}
51
+ */
52
+ export function stopConsole () {
53
+ this.log.debug('Stopping to listen for JavaScript console');
54
+ this.removeClientEventListener('Console.messageAdded');
55
+ this.removeClientEventListener('Console.messageRepeatCountUpdated');
56
+ }
57
+
58
+ /**
59
+ * @this {RemoteDebugger}
60
+ * @param {import('../types').EventListener} listener
61
+ * @returns {void}
62
+ */
63
+ export function startNetwork (listener) {
64
+ this.log.debug('Starting to listen for network events');
65
+ this.addClientEventListener('NetworkEvent', listener);
66
+ }
67
+
68
+ /**
69
+ * @this {RemoteDebugger}
70
+ * @returns {void}
71
+ */
72
+ export function stopNetwork () {
73
+ this.log.debug('Stopping to listen for network events');
74
+ this.removeClientEventListener('NetworkEvent');
75
+ }
76
+
33
77
  export default events;
34
78
 
35
79
  /**
@@ -1,10 +1,20 @@
1
1
  import { errors } from '@appium/base-driver';
2
- import { checkParams, simpleStringify, convertResult, RESPONSE_LOG_LENGTH } from '../utils';
2
+ import {
3
+ checkParams,
4
+ simpleStringify,
5
+ convertResult,
6
+ RESPONSE_LOG_LENGTH,
7
+ } from '../utils';
3
8
  import { getScriptForAtom } from '../atoms';
4
9
  import { util, timing } from '@appium/support';
5
10
  import { retryInterval } from 'asyncbox';
6
11
  import _ from 'lodash';
7
-
12
+ import {
13
+ getAppIdKey,
14
+ getPageIdKey,
15
+ getPageLoading,
16
+ getGarbageCollectOnExecute,
17
+ } from './property-accessors';
8
18
 
9
19
  /* How many milliseconds to wait for webkit to return a response before timing out */
10
20
  const RPC_RESPONSE_TIMEOUT_MS = 5000;
@@ -36,8 +46,8 @@ export async function executeAtom (atom, args = [], frames = []) {
36
46
  export async function executeAtomAsync (atom, args = [], frames = []) {
37
47
  // helper to send directly to the web inspector
38
48
  const evaluate = async (method, opts) => await this.requireRpcClient(true).send(method, Object.assign({
39
- appIdKey: this.appIdKey,
40
- pageIdKey: this.pageIdKey,
49
+ appIdKey: getAppIdKey(this),
50
+ pageIdKey: getPageIdKey(this),
41
51
  returnByValue: false,
42
52
  }, opts));
43
53
 
@@ -125,19 +135,19 @@ export async function executeAtomAsync (atom, args = [], frames = []) {
125
135
  */
126
136
  export async function execute (command, override) {
127
137
  // if the page is not loaded yet, wait for it
128
- if (this.pageLoading && !override) {
138
+ if (getPageLoading(this) && !override) {
129
139
  this.log.debug('Trying to execute but page is not loaded.');
130
140
  await this.waitForDom();
131
141
  }
132
142
 
133
- if (_.isNil(this.appIdKey)) {
143
+ if (_.isNil(getAppIdKey(this))) {
134
144
  throw new Error('Missing parameter: appIdKey. Is the target web application still alive?');
135
145
  }
136
- if (_.isNil(this.pageIdKey)) {
146
+ if (_.isNil(getPageIdKey(this))) {
137
147
  throw new Error('Missing parameter: pageIdKey. Is the target web page still alive?');
138
148
  }
139
149
 
140
- if (this.garbageCollectOnExecute) {
150
+ if (getGarbageCollectOnExecute(this)) {
141
151
  await this.garbageCollect();
142
152
  }
143
153
 
@@ -145,8 +155,8 @@ export async function execute (command, override) {
145
155
  const res = await this.requireRpcClient(true).send('Runtime.evaluate', {
146
156
  expression: command,
147
157
  returnByValue: true,
148
- appIdKey: this.appIdKey,
149
- pageIdKey: this.pageIdKey,
158
+ appIdKey: getAppIdKey(this),
159
+ pageIdKey: getPageIdKey(this),
150
160
  });
151
161
  return convertResult(res);
152
162
  }
@@ -158,9 +168,12 @@ export async function execute (command, override) {
158
168
  * @param {any[]} [args]
159
169
  */
160
170
  export async function callFunction (objectId, fn, args) {
161
- checkParams({appIdKey: this.appIdKey, pageIdKey: this.pageIdKey});
171
+ checkParams({
172
+ appIdKey: getAppIdKey(this),
173
+ pageIdKey: getPageIdKey(this),
174
+ });
162
175
 
163
- if (this.garbageCollectOnExecute) {
176
+ if (getGarbageCollectOnExecute(this)) {
164
177
  await this.garbageCollect();
165
178
  }
166
179
 
@@ -170,8 +183,8 @@ export async function callFunction (objectId, fn, args) {
170
183
  functionDeclaration: fn,
171
184
  arguments: args,
172
185
  returnByValue: true,
173
- appIdKey: this.appIdKey,
174
- pageIdKey: this.pageIdKey,
186
+ appIdKey: getAppIdKey(this),
187
+ pageIdKey: getPageIdKey(this),
175
188
  });
176
189
 
177
190
  return convertResult(res);
@@ -4,7 +4,16 @@ import {
4
4
  appInfoFromDict,
5
5
  } from '../utils';
6
6
  import _ from 'lodash';
7
-
7
+ import {
8
+ setAppIdKey,
9
+ getAppDict,
10
+ getAppIdKey,
11
+ getBundleId,
12
+ getNavigatingToPage,
13
+ setCurrentState,
14
+ setConnectedDrivers,
15
+ getSkippedApps,
16
+ } from './property-accessors';
8
17
 
9
18
  /*
10
19
  * Generic callbacks used throughout the lifecycle of the Remote Debugger.
@@ -26,8 +35,8 @@ export async function onPageChange (err, appIdKey, pageDict) {
26
35
 
27
36
  const currentPages = pageArrayFromDict(pageDict);
28
37
  // save the page dict for this app
29
- if (this.appDict[appIdKey]) {
30
- const previousPages = this.appDict[appIdKey].pageArray;
38
+ if (getAppDict(this)[appIdKey]) {
39
+ const previousPages = getAppDict(this)[appIdKey].pageArray;
31
40
  // we have a pre-existing pageDict
32
41
  if (previousPages && _.isEqual(previousPages, currentPages)) {
33
42
  this.log.debug(
@@ -37,13 +46,13 @@ export async function onPageChange (err, appIdKey, pageDict) {
37
46
  return;
38
47
  }
39
48
  // keep track of the page dictionary
40
- this.appDict[appIdKey].pageArray = currentPages;
49
+ getAppDict(this)[appIdKey].pageArray = currentPages;
41
50
  this.log.debug(
42
51
  `Pages changed for ${appIdKey}: ${JSON.stringify(previousPages)} -> ${JSON.stringify(currentPages)}`
43
52
  );
44
53
  }
45
54
 
46
- if (this._navigatingToPage) {
55
+ if (getNavigatingToPage(this)) {
47
56
  // in the middle of navigating, so reporting a page change will cause problems
48
57
  return;
49
58
  }
@@ -76,22 +85,21 @@ export async function onAppConnect (err, dict) {
76
85
  export function onAppDisconnect (err, dict) {
77
86
  const appIdKey = dict.WIRApplicationIdentifierKey;
78
87
  this.log.debug(`Application '${appIdKey}' disconnected. Removing from app dictionary.`);
79
- this.log.debug(`Current app is '${this.appIdKey}'`);
88
+ this.log.debug(`Current app is '${getAppIdKey(this)}'`);
80
89
 
81
90
  // get rid of the entry in our app dictionary,
82
91
  // since it is no longer available
83
- delete this.appDict[appIdKey];
92
+ delete getAppDict(this)[appIdKey];
84
93
 
85
94
  // if the disconnected app is the one we are connected to, try to find another
86
- if (this.appIdKey === appIdKey) {
95
+ if (getAppIdKey(this) === appIdKey) {
87
96
  this.log.debug(`No longer have app id. Attempting to find new one.`);
88
- this.appIdKey = getDebuggerAppKey.bind(this)(/** @type {string} */ (this.bundleId));
97
+ setAppIdKey(this, getDebuggerAppKey.bind(this)(/** @type {string} */ (getBundleId(this))));
89
98
  }
90
99
 
91
- if (!this.appDict) {
100
+ if (_.isEmpty(getAppDict(this))) {
92
101
  // this means we no longer have any apps. what the what?
93
102
  this.log.debug('Main app disconnected. Disconnecting altogether.');
94
- this.connected = false;
95
103
  this.emit(events.EVENT_DISCONNECT, true);
96
104
  }
97
105
  }
@@ -115,7 +123,7 @@ export async function onAppUpdate (err, dict) {
115
123
  * @returns {void}
116
124
  */
117
125
  export function onConnectedDriverList (err, drivers) {
118
- this.connectedDrivers = drivers.WIRDriverDictionaryKey;
126
+ setConnectedDrivers(this, drivers.WIRDriverDictionaryKey);
119
127
  this.log.debug(`Received connected driver list: ${JSON.stringify(this.connectedDrivers)}`);
120
128
  }
121
129
 
@@ -126,7 +134,7 @@ export function onConnectedDriverList (err, drivers) {
126
134
  * @returns {void}
127
135
  */
128
136
  export function onCurrentState (err, state) {
129
- this.currentState = state.WIRAutomationAvailabilityKey;
137
+ setCurrentState(this, state.WIRAutomationAvailabilityKey);
130
138
  // This state changes when 'Remote Automation' in 'Settings app' > 'Safari' > 'Advanced' > 'Remote Automation' changes
131
139
  // WIRAutomationAvailabilityAvailable or WIRAutomationAvailabilityNotAvailable
132
140
  this.log.debug(`Received connected automation availability state: ${JSON.stringify(this.currentState)}`);
@@ -147,13 +155,13 @@ export async function onConnectedApplicationList (err, apps) {
147
155
  let newDict = {};
148
156
  for (const dict of _.values(apps)) {
149
157
  const [id, entry] = appInfoFromDict(dict);
150
- if (this.skippedApps.includes(entry.name)) {
158
+ if (getSkippedApps(this).includes(entry.name)) {
151
159
  continue;
152
160
  }
153
161
  newDict[id] = entry;
154
162
  }
155
163
  // update the object's list of apps
156
- _.defaults(this.appDict, newDict);
164
+ _.defaults(getAppDict(this), newDict);
157
165
  }
158
166
 
159
167
  /**
@@ -165,17 +173,16 @@ export async function onConnectedApplicationList (err, apps) {
165
173
  function updateAppsWithDict (dict) {
166
174
  // get the dictionary entry into a nice form, and add it to the
167
175
  // application dictionary
168
- this.appDict ??= {};
169
176
  const [id, entry] = appInfoFromDict(dict);
170
- if (this.appDict[id]) {
177
+ if (getAppDict(this)[id]) {
171
178
  // preserve the page dictionary for this entry
172
- entry.pageArray = this.appDict[id].pageArray;
179
+ entry.pageArray = getAppDict(this)[id].pageArray;
173
180
  }
174
- this.appDict[id] = entry;
181
+ getAppDict(this)[id] = entry;
175
182
 
176
183
  // try to get the app id from our connected apps
177
- if (!this.appIdKey) {
178
- this.appIdKey = getDebuggerAppKey.bind(this)(/** @type {string} */ (this.bundleId));
184
+ if (!getAppIdKey(this)) {
185
+ setAppIdKey(this, getDebuggerAppKey.bind(this)(/** @type {string} */ (getBundleId(this))));
179
186
  }
180
187
  }
181
188
 
@@ -189,7 +196,7 @@ function updateAppsWithDict (dict) {
189
196
  */
190
197
  export function getDebuggerAppKey (bundleId) {
191
198
  let appId;
192
- for (const [key, data] of _.toPairs(this.appDict)) {
199
+ for (const [key, data] of _.toPairs(getAppDict(this))) {
193
200
  if (data.bundleId === bundleId) {
194
201
  appId = key;
195
202
  break;
@@ -199,7 +206,7 @@ export function getDebuggerAppKey (bundleId) {
199
206
  if (appId) {
200
207
  this.log.debug(`Found app id key '${appId}' for bundle '${bundleId}'`);
201
208
  let proxyAppId;
202
- for (const [key, data] of _.toPairs(this.appDict)) {
209
+ for (const [key, data] of _.toPairs(getAppDict(this))) {
203
210
  if (data.isProxy && data.hostId === appId) {
204
211
  this.log.debug(`Found separate bundleId '${data.bundleId}' ` +
205
212
  `acting as proxy for '${bundleId}', with app id '${key}'`);