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.
- package/CHANGELOG.md +51 -0
- package/build/lib/mixins/connect.d.ts +2 -45
- package/build/lib/mixins/connect.d.ts.map +1 -1
- package/build/lib/mixins/connect.js +46 -46
- package/build/lib/mixins/connect.js.map +1 -1
- package/build/lib/mixins/cookies.d.ts.map +1 -1
- package/build/lib/mixins/cookies.js +8 -7
- package/build/lib/mixins/cookies.js.map +1 -1
- package/build/lib/mixins/events.d.ts +27 -5
- package/build/lib/mixins/events.d.ts.map +1 -1
- package/build/lib/mixins/events.js +47 -6
- package/build/lib/mixins/events.js.map +1 -1
- package/build/lib/mixins/execute.d.ts.map +1 -1
- package/build/lib/mixins/execute.js +16 -12
- package/build/lib/mixins/execute.js.map +1 -1
- package/build/lib/mixins/message-handlers.d.ts +0 -31
- package/build/lib/mixins/message-handlers.d.ts.map +1 -1
- package/build/lib/mixins/message-handlers.js +21 -22
- package/build/lib/mixins/message-handlers.js.map +1 -1
- package/build/lib/mixins/misc.d.ts +2 -24
- package/build/lib/mixins/misc.d.ts.map +1 -1
- package/build/lib/mixins/misc.js +15 -51
- package/build/lib/mixins/misc.js.map +1 -1
- package/build/lib/mixins/navigate.d.ts +1 -25
- package/build/lib/mixins/navigate.d.ts.map +1 -1
- package/build/lib/mixins/navigate.js +36 -30
- package/build/lib/mixins/navigate.js.map +1 -1
- package/build/lib/mixins/property-accessors.d.ts +27 -0
- package/build/lib/mixins/property-accessors.d.ts.map +1 -0
- package/build/lib/mixins/property-accessors.js +95 -0
- package/build/lib/mixins/property-accessors.js.map +1 -0
- package/build/lib/mixins/screenshot.d.ts.map +1 -1
- package/build/lib/mixins/screenshot.js +3 -2
- package/build/lib/mixins/screenshot.js.map +1 -1
- package/build/lib/remote-debugger-real-device.d.ts +7 -19
- package/build/lib/remote-debugger-real-device.d.ts.map +1 -1
- package/build/lib/remote-debugger-real-device.js +12 -20
- package/build/lib/remote-debugger-real-device.js.map +1 -1
- package/build/lib/remote-debugger.d.ts +63 -167
- package/build/lib/remote-debugger.d.ts.map +1 -1
- package/build/lib/remote-debugger.js +75 -119
- package/build/lib/remote-debugger.js.map +1 -1
- package/build/lib/types.d.ts +41 -1
- package/build/lib/types.d.ts.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/mixins/connect.js +66 -52
- package/lib/mixins/cookies.js +11 -7
- package/lib/mixins/events.js +50 -6
- package/lib/mixins/execute.js +27 -14
- package/lib/mixins/message-handlers.js +30 -23
- package/lib/mixins/misc.js +18 -51
- package/lib/mixins/navigate.js +44 -30
- package/lib/mixins/property-accessors.ts +96 -0
- package/lib/mixins/screenshot.js +7 -2
- package/lib/remote-debugger-real-device.ts +28 -0
- package/lib/remote-debugger.ts +268 -0
- package/lib/types.ts +44 -1
- package/package.json +1 -1
- package/lib/remote-debugger-real-device.js +0 -39
- package/lib/remote-debugger.js +0 -299
package/lib/mixins/connect.js
CHANGED
|
@@ -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('
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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 (
|
|
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
|
|
124
|
-
if (this
|
|
125
|
-
this.log.debug(`Received altered app id, updating from '${this
|
|
126
|
-
this
|
|
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
|
|
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
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
|
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
|
|
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 =
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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}' ` +
|
package/lib/mixins/cookies.js
CHANGED
|
@@ -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
|
|
11
|
-
pageIdKey: this
|
|
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
|
|
25
|
-
pageIdKey: this
|
|
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
|
|
41
|
-
pageIdKey: this
|
|
44
|
+
appIdKey: getAppIdKey(this),
|
|
45
|
+
pageIdKey: getPageIdKey(this),
|
|
42
46
|
cookieName,
|
|
43
47
|
url,
|
|
44
48
|
});
|
package/lib/mixins/events.js
CHANGED
|
@@ -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 {
|
|
17
|
+
* @param {import('../types').EventListener} listener
|
|
14
18
|
* @returns {void}
|
|
15
19
|
*/
|
|
16
20
|
export function addClientEventListener (eventName, listener) {
|
|
17
|
-
this
|
|
18
|
-
this
|
|
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
|
|
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
|
/**
|
package/lib/mixins/execute.js
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
import { errors } from '@appium/base-driver';
|
|
2
|
-
import {
|
|
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
|
|
40
|
-
pageIdKey: this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
149
|
-
pageIdKey: this
|
|
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({
|
|
171
|
+
checkParams({
|
|
172
|
+
appIdKey: getAppIdKey(this),
|
|
173
|
+
pageIdKey: getPageIdKey(this),
|
|
174
|
+
});
|
|
162
175
|
|
|
163
|
-
if (this
|
|
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
|
|
174
|
-
pageIdKey: this
|
|
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
|
|
30
|
-
const previousPages = this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
95
|
+
if (getAppIdKey(this) === appIdKey) {
|
|
87
96
|
this.log.debug(`No longer have app id. Attempting to find new one.`);
|
|
88
|
-
this
|
|
97
|
+
setAppIdKey(this, getDebuggerAppKey.bind(this)(/** @type {string} */ (getBundleId(this))));
|
|
89
98
|
}
|
|
90
99
|
|
|
91
|
-
if (
|
|
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
|
|
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
|
|
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.
|
|
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
|
|
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
|
|
177
|
+
if (getAppDict(this)[id]) {
|
|
171
178
|
// preserve the page dictionary for this entry
|
|
172
|
-
entry.pageArray = this
|
|
179
|
+
entry.pageArray = getAppDict(this)[id].pageArray;
|
|
173
180
|
}
|
|
174
|
-
this
|
|
181
|
+
getAppDict(this)[id] = entry;
|
|
175
182
|
|
|
176
183
|
// try to get the app id from our connected apps
|
|
177
|
-
if (!this
|
|
178
|
-
this
|
|
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
|
|
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
|
|
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}'`);
|