appium-remote-debugger 15.3.4 → 15.3.5
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 +6 -0
- package/build/lib/atoms.d.ts.map +1 -1
- package/build/lib/atoms.js +2 -2
- package/build/lib/atoms.js.map +1 -1
- package/build/lib/index.d.ts.map +1 -1
- package/build/lib/index.js.map +1 -1
- package/build/lib/logger.js.map +1 -1
- package/build/lib/mixins/connect.d.ts.map +1 -1
- package/build/lib/mixins/connect.js +11 -8
- 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.map +1 -1
- package/build/lib/mixins/events.d.ts.map +1 -1
- package/build/lib/mixins/events.js +1 -1
- 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 +2 -2
- package/build/lib/mixins/execute.js.map +1 -1
- package/build/lib/mixins/message-handlers.d.ts.map +1 -1
- package/build/lib/mixins/message-handlers.js.map +1 -1
- package/build/lib/mixins/misc.d.ts.map +1 -1
- package/build/lib/mixins/misc.js +1 -1
- package/build/lib/mixins/misc.js.map +1 -1
- package/build/lib/mixins/navigate.d.ts.map +1 -1
- package/build/lib/mixins/navigate.js +2 -3
- package/build/lib/mixins/navigate.js.map +1 -1
- package/build/lib/mixins/property-accessors.d.ts +20 -20
- package/build/lib/mixins/property-accessors.d.ts.map +1 -1
- package/build/lib/mixins/property-accessors.js.map +1 -1
- package/build/lib/mixins/screenshot.d.ts.map +1 -1
- package/build/lib/mixins/screenshot.js +5 -1
- package/build/lib/mixins/screenshot.js.map +1 -1
- package/build/lib/protocol/index.d.ts.map +1 -1
- package/build/lib/protocol/index.js +2 -3
- package/build/lib/protocol/index.js.map +1 -1
- package/build/lib/remote-debugger-real-device.d.ts.map +1 -1
- package/build/lib/remote-debugger-real-device.js.map +1 -1
- package/build/lib/remote-debugger.d.ts.map +1 -1
- package/build/lib/remote-debugger.js +3 -1
- package/build/lib/remote-debugger.js.map +1 -1
- package/build/lib/rpc/index.d.ts.map +1 -1
- package/build/lib/rpc/index.js.map +1 -1
- package/build/lib/rpc/remote-messages.d.ts.map +1 -1
- package/build/lib/rpc/remote-messages.js +16 -15
- package/build/lib/rpc/remote-messages.js.map +1 -1
- package/build/lib/rpc/rpc-client-real-device.d.ts.map +1 -1
- package/build/lib/rpc/rpc-client-real-device.js.map +1 -1
- package/build/lib/rpc/rpc-client-simulator.d.ts.map +1 -1
- package/build/lib/rpc/rpc-client-simulator.js +3 -4
- package/build/lib/rpc/rpc-client-simulator.js.map +1 -1
- package/build/lib/rpc/rpc-client.d.ts.map +1 -1
- package/build/lib/rpc/rpc-client.js +6 -6
- package/build/lib/rpc/rpc-client.js.map +1 -1
- package/build/lib/rpc/rpc-message-handler.d.ts.map +1 -1
- package/build/lib/rpc/rpc-message-handler.js +3 -4
- package/build/lib/rpc/rpc-message-handler.js.map +1 -1
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +6 -5
- package/build/lib/utils.js.map +1 -1
- package/lib/atoms.ts +8 -6
- package/lib/index.ts +11 -11
- package/lib/logger.ts +1 -1
- package/lib/mixins/connect.ts +63 -47
- package/lib/mixins/cookies.ts +5 -11
- package/lib/mixins/events.ts +8 -19
- package/lib/mixins/execute.ts +43 -35
- package/lib/mixins/message-handlers.ts +21 -20
- package/lib/mixins/misc.ts +12 -15
- package/lib/mixins/navigate.ts +68 -61
- package/lib/mixins/property-accessors.ts +48 -23
- package/lib/mixins/screenshot.ts +10 -11
- package/lib/protocol/index.ts +11 -9
- package/lib/remote-debugger-real-device.ts +5 -5
- package/lib/remote-debugger.ts +22 -28
- package/lib/rpc/index.ts +2 -2
- package/lib/rpc/remote-messages.ts +48 -48
- package/lib/rpc/rpc-client-real-device.ts +4 -4
- package/lib/rpc/rpc-client-simulator.ts +23 -20
- package/lib/rpc/rpc-client.ts +161 -108
- package/lib/rpc/rpc-message-handler.ts +34 -24
- package/lib/types.ts +3 -3
- package/lib/utils.ts +24 -17
- package/package.json +3 -1
package/build/lib/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAKvB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAKvB,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAC,MAAM,SAAS,CAAC;AAGpD,eAAO,MAAM,qBAAqB,gCAAgC,CAAC;AAQnE,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CA8B5E;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,EAAE,CAchE;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAW5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAShE;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,GAAE,OAAe,GAAG,MAAM,CAO9E;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAyB/D;AAED;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,SAAuC,MAAM,sBAMrE,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAGlD"}
|
package/build/lib/utils.js
CHANGED
|
@@ -44,9 +44,10 @@ function appInfoFromDict(dict) {
|
|
|
44
44
|
let isAutomationEnabled = !!dict.WIRRemoteAutomationEnabledKey;
|
|
45
45
|
if (lodash_1.default.has(dict, 'WIRAutomationAvailabilityKey')) {
|
|
46
46
|
if (lodash_1.default.isString(dict.WIRAutomationAvailabilityKey)) {
|
|
47
|
-
isAutomationEnabled =
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
isAutomationEnabled =
|
|
48
|
+
dict.WIRAutomationAvailabilityKey === 'WIRAutomationAvailabilityUnknown'
|
|
49
|
+
? 'Unknown'
|
|
50
|
+
: dict.WIRAutomationAvailabilityKey === 'WIRAutomationAvailabilityAvailable';
|
|
50
51
|
}
|
|
51
52
|
else {
|
|
52
53
|
isAutomationEnabled = !!dict.WIRAutomationAvailabilityKey;
|
|
@@ -71,7 +72,7 @@ function appInfoFromDict(dict) {
|
|
|
71
72
|
* @returns An array of Page objects representing the available pages.
|
|
72
73
|
*/
|
|
73
74
|
function pageArrayFromDict(pageDict) {
|
|
74
|
-
return lodash_1.default.values(pageDict)
|
|
75
|
+
return (lodash_1.default.values(pageDict)
|
|
75
76
|
// count only WIRTypeWeb pages and ignore all others (WIRTypeJavaScript etc)
|
|
76
77
|
.filter((dict) => lodash_1.default.isUndefined(dict.WIRTypeKey) || ACCEPTED_PAGE_TYPES.includes(dict.WIRTypeKey))
|
|
77
78
|
.map((dict) => ({
|
|
@@ -79,7 +80,7 @@ function pageArrayFromDict(pageDict) {
|
|
|
79
80
|
title: dict.WIRTitleKey,
|
|
80
81
|
url: dict.WIRURLKey,
|
|
81
82
|
isKey: !lodash_1.default.isUndefined(dict.WIRConnectionIdentifierKey),
|
|
82
|
-
}));
|
|
83
|
+
})));
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Finds all application identifier keys that match the given bundle ID.
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;;;;AA0BA,
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;;;;AA0BA,0CA8BC;AASD,8CAcC;AAWD,0CAWC;AAWD,kCASC;AAUD,0CAOC;AAYD,8EAyBC;AAsBD,kDAGC;AAxMD,oDAAuB;AACvB,qDAA+D;AAC/D,6CAA2C;AAC3C,sDAA6B;AAC7B,0DAA6B;AAI7B,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAChC,QAAA,qBAAqB,GAAG,6BAA6B,CAAC;AACnE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,yCAAyC;AACzC,MAAM,mBAAmB,GAAG;IAC1B,YAAY,EAAE,iBAAiB;IAC/B,gBAAgB,EAAE,WAAW;IAC7B,aAAa,EAAE,mBAAmB;CACnC,CAAC;AACW,QAAA,mBAAmB,GAAG,GAAG,CAAC;AAEvC;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,IAAyB;IACvD,MAAM,EAAE,GAAG,IAAI,CAAC,2BAA2B,CAAC;IAC5C,MAAM,OAAO,GAAG,gBAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,wBAAwB,CAAC;QACvD,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,WAAW,EAAE,KAAK,MAAM;QACxD,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC;IAClC,iDAAiD;IACjD,8CAA8C;IAC9C,uDAAuD;IACvD,IAAI,mBAAmB,GAAqB,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC;IACjF,IAAI,gBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,8BAA8B,CAAC,EAAE,CAAC;Q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C,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC;IACpD,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;GAMG;AACU,QAAA,aAAa,GAAG,gBAAC,CAAC,OAAO,CAAC,SAAS,aAAa;IAC3D,MAAM,IAAI,GAAG,cAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE,UAAU,CAAC,CAAC;IAC7D,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,sCAAsC,WAAW,iBAAiB,CAAC,CAAC;IACtF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;GAIG;AACH,SAAgB,mBAAmB;IACjC,MAAM,QAAQ,GAAG,mBAAI,CAAC,OAAO,CAAC,IAAA,qBAAa,GAAE,EAAE,cAAc,CAAC,CAAC;IAC/D,OAAO,IAAI,CAAC,KAAK,CAAC,iBAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAI,GAAM;IACtC,IAAI,gBAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACpB,KAAK,MAAM,QAAQ,IAAI,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,CAAC;YAChF,OAAO,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/lib/atoms.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {fs} from '@appium/support';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import _ from 'lodash';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import {log} from './logger';
|
|
5
|
+
import {getModuleRoot} from './utils';
|
|
6
6
|
|
|
7
7
|
const ATOMS_CACHE: Record<string, Buffer> = {};
|
|
8
8
|
|
|
@@ -52,8 +52,10 @@ export async function getAtom(atomName: string): Promise<Buffer> {
|
|
|
52
52
|
async function wrapScriptForFrame(script: string, frame: string): Promise<string> {
|
|
53
53
|
log.debug(`Wrapping script for frame '${frame}'`);
|
|
54
54
|
const elFromCache = await getAtom('get_element_from_cache');
|
|
55
|
-
return
|
|
56
|
-
`
|
|
55
|
+
return (
|
|
56
|
+
`(function (window) { var document = window.document; ` +
|
|
57
|
+
`return (${script}); })((${elFromCache.toString('utf8')})(${atomsStringify(frame)}))`
|
|
58
|
+
);
|
|
57
59
|
}
|
|
58
60
|
|
|
59
61
|
/**
|
|
@@ -72,7 +74,7 @@ export async function getScriptForAtom(
|
|
|
72
74
|
atom: string,
|
|
73
75
|
args: any[] = [],
|
|
74
76
|
frames: string[] = [],
|
|
75
|
-
asyncCallBack: string | null = null
|
|
77
|
+
asyncCallBack: string | null = null,
|
|
76
78
|
): Promise<string> {
|
|
77
79
|
const atomSrc = (await getAtom(atom)).toString('utf8');
|
|
78
80
|
let script: string;
|
package/lib/index.ts
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import {RemoteDebugger, REMOTE_DEBUGGER_PORT} from './remote-debugger';
|
|
2
|
+
import {RemoteDebuggerRealDevice} from './remote-debugger-real-device';
|
|
3
|
+
import type {RemoteDebuggerRealDeviceOptions, RemoteDebuggerOptions} from './types';
|
|
4
4
|
|
|
5
|
-
export function createRemoteDebugger
|
|
5
|
+
export function createRemoteDebugger(
|
|
6
6
|
opts: RemoteDebuggerRealDeviceOptions,
|
|
7
|
-
realDevice: true
|
|
7
|
+
realDevice: true,
|
|
8
8
|
): RemoteDebuggerRealDevice;
|
|
9
|
-
export function createRemoteDebugger
|
|
9
|
+
export function createRemoteDebugger(
|
|
10
10
|
opts: RemoteDebuggerOptions,
|
|
11
|
-
realDevice: false
|
|
11
|
+
realDevice: false,
|
|
12
12
|
): RemoteDebugger;
|
|
13
|
-
export function createRemoteDebugger
|
|
13
|
+
export function createRemoteDebugger(
|
|
14
14
|
opts: RemoteDebuggerRealDeviceOptions | RemoteDebuggerOptions,
|
|
15
|
-
realDevice: boolean
|
|
15
|
+
realDevice: boolean,
|
|
16
16
|
): RemoteDebuggerRealDevice | RemoteDebugger {
|
|
17
17
|
return realDevice
|
|
18
18
|
? new RemoteDebuggerRealDevice(opts as RemoteDebuggerRealDeviceOptions)
|
|
19
19
|
: new RemoteDebugger(opts as RemoteDebuggerOptions);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export {
|
|
23
|
-
export type {
|
|
22
|
+
export {RemoteDebugger, RemoteDebuggerRealDevice, REMOTE_DEBUGGER_PORT};
|
|
23
|
+
export type {RemoteDebuggerRealDeviceOptions, RemoteDebuggerOptions};
|
package/lib/logger.ts
CHANGED
package/lib/mixins/connect.ts
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from '../utils';
|
|
6
|
-
import { events } from './events';
|
|
7
|
-
import { timing, util } from '@appium/support';
|
|
8
|
-
import { retryInterval, waitForCondition } from 'asyncbox';
|
|
1
|
+
import {pageArrayFromDict, WEB_CONTENT_BUNDLE_ID, appIdsForBundle} from '../utils';
|
|
2
|
+
import {events} from './events';
|
|
3
|
+
import {timing, util} from '@appium/support';
|
|
4
|
+
import {retryInterval, waitForCondition} from 'asyncbox';
|
|
9
5
|
import _ from 'lodash';
|
|
10
6
|
import {
|
|
11
7
|
setAppIdKey,
|
|
@@ -18,9 +14,9 @@ import {
|
|
|
18
14
|
getBundleId,
|
|
19
15
|
getAdditionalBundleIds,
|
|
20
16
|
} from './property-accessors';
|
|
21
|
-
import {
|
|
22
|
-
import type {
|
|
23
|
-
import type {
|
|
17
|
+
import {NEW_APP_CONNECTED_ERROR, EMPTY_PAGE_DICTIONARY_ERROR} from '../rpc/rpc-client';
|
|
18
|
+
import type {RemoteDebugger} from '../remote-debugger';
|
|
19
|
+
import type {AppDict, Page, AppIdKey, PageIdKey, AppPage} from '../types';
|
|
24
20
|
|
|
25
21
|
const APP_CONNECT_TIMEOUT_MS = 0;
|
|
26
22
|
const APP_CONNECT_INTERVAL_MS = 100;
|
|
@@ -57,7 +53,10 @@ export async function setConnectionKey(this: RemoteDebugger): Promise<void> {
|
|
|
57
53
|
* @returns A promise that resolves to the application dictionary containing all
|
|
58
54
|
* connected applications.
|
|
59
55
|
*/
|
|
60
|
-
export async function connect(
|
|
56
|
+
export async function connect(
|
|
57
|
+
this: RemoteDebugger,
|
|
58
|
+
timeout: number = APP_CONNECT_TIMEOUT_MS,
|
|
59
|
+
): Promise<AppDict> {
|
|
61
60
|
this.setup();
|
|
62
61
|
|
|
63
62
|
// initialize the rpc client
|
|
@@ -91,7 +90,7 @@ export async function connect(this: RemoteDebugger, timeout: number = APP_CONNEC
|
|
|
91
90
|
});
|
|
92
91
|
this.log.debug(
|
|
93
92
|
`Retrieved ${util.pluralize('application', _.size(getAppDict(this)), true)} ` +
|
|
94
|
-
|
|
93
|
+
`within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`,
|
|
95
94
|
);
|
|
96
95
|
} catch {
|
|
97
96
|
this.log.debug(`Timed out waiting for applications to be reported`);
|
|
@@ -134,7 +133,7 @@ export async function selectApp(
|
|
|
134
133
|
this: RemoteDebugger,
|
|
135
134
|
currentUrl: string | null = null,
|
|
136
135
|
maxTries: number = SELECT_APP_RETRIES,
|
|
137
|
-
ignoreAboutBlankUrl: boolean = false
|
|
136
|
+
ignoreAboutBlankUrl: boolean = false,
|
|
138
137
|
): Promise<Page[]> {
|
|
139
138
|
this.log.debug('Selecting application');
|
|
140
139
|
|
|
@@ -144,9 +143,11 @@ export async function selectApp(
|
|
|
144
143
|
return [];
|
|
145
144
|
}
|
|
146
145
|
|
|
147
|
-
const {
|
|
146
|
+
const {appIdKey} = await searchForApp.bind(this)(currentUrl, maxTries, ignoreAboutBlankUrl);
|
|
148
147
|
if (getAppIdKey(this) !== appIdKey) {
|
|
149
|
-
this.log.debug(
|
|
148
|
+
this.log.debug(
|
|
149
|
+
`Received altered app id, updating from '${getAppIdKey(this)}' to '${appIdKey}'`,
|
|
150
|
+
);
|
|
150
151
|
setAppIdKey(this, appIdKey);
|
|
151
152
|
}
|
|
152
153
|
logApplicationDictionary.bind(this)();
|
|
@@ -188,20 +189,24 @@ export async function selectPage(
|
|
|
188
189
|
this: RemoteDebugger,
|
|
189
190
|
appIdKey: AppIdKey,
|
|
190
191
|
pageIdKey: PageIdKey,
|
|
191
|
-
skipReadyCheck: boolean = false
|
|
192
|
+
skipReadyCheck: boolean = false,
|
|
192
193
|
): Promise<void> {
|
|
193
194
|
const fullAppIdKey = _.startsWith(`${appIdKey}`, 'PID:') ? `${appIdKey}` : `PID:${appIdKey}`;
|
|
194
195
|
setAppIdKey(this, fullAppIdKey);
|
|
195
196
|
setPageIdKey(this, pageIdKey);
|
|
196
197
|
|
|
197
|
-
this.log.debug(
|
|
198
|
+
this.log.debug(
|
|
199
|
+
`Selecting page '${pageIdKey}' on app '${fullAppIdKey}' and forwarding socket setup`,
|
|
200
|
+
);
|
|
198
201
|
|
|
199
202
|
const timer = new timing.Timer().start();
|
|
200
203
|
|
|
201
|
-
const pageReadinessDetector = skipReadyCheck
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
const pageReadinessDetector = skipReadyCheck
|
|
205
|
+
? undefined
|
|
206
|
+
: {
|
|
207
|
+
timeoutMs: this.pageLoadMs,
|
|
208
|
+
readinessDetector: (readyState: string) => this.isPageLoadingCompleted(readyState),
|
|
209
|
+
};
|
|
205
210
|
await this.requireRpcClient().selectPage(fullAppIdKey, pageIdKey, pageReadinessDetector);
|
|
206
211
|
|
|
207
212
|
this.log.debug(`Selected page after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
@@ -221,7 +226,7 @@ export function getPossibleDebuggerAppKeys(this: RemoteDebugger, bundleIds: stri
|
|
|
221
226
|
|
|
222
227
|
if (bundleIds.includes(WILDCARD_BUNDLE_ID)) {
|
|
223
228
|
this.log.info(
|
|
224
|
-
'Returning all apps because the list of matching bundle identifiers includes a wildcard'
|
|
229
|
+
'Returning all apps because the list of matching bundle identifiers includes a wildcard',
|
|
225
230
|
);
|
|
226
231
|
return _.keys(appDict);
|
|
227
232
|
}
|
|
@@ -235,7 +240,7 @@ export function getPossibleDebuggerAppKeys(this: RemoteDebugger, bundleIds: stri
|
|
|
235
240
|
...bundleIds,
|
|
236
241
|
]);
|
|
237
242
|
this.log.debug(
|
|
238
|
-
`Checking for apps with matching bundle identifiers: ${possibleBundleIds.join(', ')}
|
|
243
|
+
`Checking for apps with matching bundle identifiers: ${possibleBundleIds.join(', ')}`,
|
|
239
244
|
);
|
|
240
245
|
const proxiedAppIds: string[] = [];
|
|
241
246
|
for (const bundleId of possibleBundleIds) {
|
|
@@ -251,7 +256,7 @@ export function getPossibleDebuggerAppKeys(this: RemoteDebugger, bundleIds: stri
|
|
|
251
256
|
if (data.isProxy && data.hostId === appId && !proxiedAppIds.includes(key)) {
|
|
252
257
|
this.log.debug(
|
|
253
258
|
`Found separate bundleId '${data.bundleId}' ` +
|
|
254
|
-
|
|
259
|
+
`acting as proxy for '${bundleId}', with app id '${key}'`,
|
|
255
260
|
);
|
|
256
261
|
proxiedAppIds.push(key);
|
|
257
262
|
}
|
|
@@ -261,7 +266,7 @@ export function getPossibleDebuggerAppKeys(this: RemoteDebugger, bundleIds: stri
|
|
|
261
266
|
|
|
262
267
|
this.log.debug(
|
|
263
268
|
`You may also consider providing more values to 'additionalWebviewBundleIds' ` +
|
|
264
|
-
|
|
269
|
+
`capability to match other applications. Add a wildcard ('*') to match all apps.`,
|
|
265
270
|
);
|
|
266
271
|
|
|
267
272
|
return _.uniq(proxiedAppIds);
|
|
@@ -286,28 +291,31 @@ async function searchForApp(
|
|
|
286
291
|
this: RemoteDebugger,
|
|
287
292
|
currentUrl: string | null,
|
|
288
293
|
maxTries: number,
|
|
289
|
-
ignoreAboutBlankUrl: boolean
|
|
294
|
+
ignoreAboutBlankUrl: boolean,
|
|
290
295
|
): Promise<AppPage> {
|
|
291
|
-
const bundleIds: string[] = _.compact(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
]
|
|
297
|
-
);
|
|
296
|
+
const bundleIds: string[] = _.compact([
|
|
297
|
+
getBundleId(this),
|
|
298
|
+
...(getAdditionalBundleIds(this) ?? []),
|
|
299
|
+
...(getIncludeSafari(this) && !getIsSafari(this) ? [SAFARI_BUNDLE_ID] : []),
|
|
300
|
+
]);
|
|
298
301
|
let retryCount = 0;
|
|
299
|
-
return await retryInterval(maxTries, SELECT_APP_RETRY_SLEEP_MS, async () => {
|
|
302
|
+
return (await retryInterval(maxTries, SELECT_APP_RETRY_SLEEP_MS, async () => {
|
|
300
303
|
logApplicationDictionary.bind(this)();
|
|
301
304
|
const possibleAppIds = getPossibleDebuggerAppKeys.bind(this)(bundleIds);
|
|
302
|
-
this.log.debug(
|
|
305
|
+
this.log.debug(
|
|
306
|
+
`Trying out the possible app ids: ${possibleAppIds.join(', ')} (try #${retryCount + 1} of ${maxTries})`,
|
|
307
|
+
);
|
|
303
308
|
for (const attemptedAppIdKey of possibleAppIds) {
|
|
304
309
|
const appInfo = getAppDict(this)[attemptedAppIdKey];
|
|
305
310
|
if (!appInfo) {
|
|
306
311
|
continue;
|
|
307
312
|
}
|
|
308
|
-
if (
|
|
313
|
+
if (
|
|
314
|
+
!appInfo.isActive ||
|
|
315
|
+
(!appInfo.isAutomationEnabled && appInfo.bundleId === SAFARI_BUNDLE_ID)
|
|
316
|
+
) {
|
|
309
317
|
this.log.debug(
|
|
310
|
-
`Skipping app '${attemptedAppIdKey}' because it is not ${appInfo.isActive ? 'enabled' : 'active'}
|
|
318
|
+
`Skipping app '${attemptedAppIdKey}' because it is not ${appInfo.isActive ? 'enabled' : 'active'}`,
|
|
311
319
|
);
|
|
312
320
|
continue;
|
|
313
321
|
}
|
|
@@ -328,22 +336,28 @@ async function searchForApp(
|
|
|
328
336
|
}
|
|
329
337
|
|
|
330
338
|
if (currentUrl) {
|
|
331
|
-
this.log.debug(
|
|
339
|
+
this.log.debug(
|
|
340
|
+
`Received app, but expected url ('${currentUrl}') was not found. Trying again.`,
|
|
341
|
+
);
|
|
332
342
|
} else {
|
|
333
343
|
this.log.debug('Received app, but no match was found. Trying again.');
|
|
334
344
|
}
|
|
335
345
|
} catch (err: any) {
|
|
336
|
-
if (
|
|
346
|
+
if (
|
|
347
|
+
![NEW_APP_CONNECTED_ERROR, EMPTY_PAGE_DICTIONARY_ERROR].some((msg) => msg === err.message)
|
|
348
|
+
) {
|
|
337
349
|
this.log.debug(err.stack);
|
|
338
350
|
}
|
|
339
|
-
this.log.warn(
|
|
351
|
+
this.log.warn(
|
|
352
|
+
`The application ${attemptedAppIdKey} is not connectable yet: ${err.message}`,
|
|
353
|
+
);
|
|
340
354
|
}
|
|
341
355
|
}
|
|
342
356
|
retryCount++;
|
|
343
357
|
throw new Error(
|
|
344
|
-
`Could not connect to a valid webapp. Make sure it is debuggable and has at least one active page
|
|
358
|
+
`Could not connect to a valid webapp. Make sure it is debuggable and has at least one active page.`,
|
|
345
359
|
);
|
|
346
|
-
}) as Promise<AppPage>;
|
|
360
|
+
})) as Promise<AppPage>;
|
|
347
361
|
}
|
|
348
362
|
|
|
349
363
|
/**
|
|
@@ -360,7 +374,7 @@ function searchForPage(
|
|
|
360
374
|
this: RemoteDebugger,
|
|
361
375
|
appsDict: AppDict,
|
|
362
376
|
currentUrl: string | null = null,
|
|
363
|
-
ignoreAboutBlankUrl: boolean = false
|
|
377
|
+
ignoreAboutBlankUrl: boolean = false,
|
|
364
378
|
): AppPage | null {
|
|
365
379
|
for (const appDict of _.values(appsDict)) {
|
|
366
380
|
if (!appDict || !appDict.isActive || !appDict.pageArray || _.isEmpty(appDict.pageArray)) {
|
|
@@ -368,11 +382,13 @@ function searchForPage(
|
|
|
368
382
|
}
|
|
369
383
|
|
|
370
384
|
for (const page of appDict.pageArray) {
|
|
371
|
-
if (
|
|
372
|
-
|
|
385
|
+
if (
|
|
386
|
+
(!ignoreAboutBlankUrl || page.url !== BLANK_PAGE_URL) &&
|
|
387
|
+
(!currentUrl || page.url === currentUrl || page.url === `${currentUrl}/`)
|
|
388
|
+
) {
|
|
373
389
|
return {
|
|
374
390
|
appIdKey: appDict.id,
|
|
375
|
-
pageDict: page
|
|
391
|
+
pageDict: page,
|
|
376
392
|
};
|
|
377
393
|
}
|
|
378
394
|
}
|
package/lib/mixins/cookies.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from './property-accessors';
|
|
5
|
-
import type { RemoteDebugger } from '../remote-debugger';
|
|
6
|
-
import type { StringRecord } from '@appium/types';
|
|
1
|
+
import {getAppIdKey, getPageIdKey} from './property-accessors';
|
|
2
|
+
import type {RemoteDebugger} from '../remote-debugger';
|
|
3
|
+
import type {StringRecord} from '@appium/types';
|
|
7
4
|
|
|
8
5
|
/**
|
|
9
6
|
* Retrieves all cookies for the current page by sending a Page.getCookies
|
|
@@ -26,10 +23,7 @@ export async function getCookies(this: RemoteDebugger): Promise<StringRecord> {
|
|
|
26
23
|
* @param cookie - Dictionary containing the cookie properties to set.
|
|
27
24
|
* @returns A promise that resolves when the cookie has been set.
|
|
28
25
|
*/
|
|
29
|
-
export async function setCookie(
|
|
30
|
-
this: RemoteDebugger,
|
|
31
|
-
cookie: StringRecord
|
|
32
|
-
): Promise<any> {
|
|
26
|
+
export async function setCookie(this: RemoteDebugger, cookie: StringRecord): Promise<any> {
|
|
33
27
|
this.log.debug('Setting cookie');
|
|
34
28
|
return await this.requireRpcClient().send('Page.setCookie', {
|
|
35
29
|
appIdKey: getAppIdKey(this),
|
|
@@ -49,7 +43,7 @@ export async function setCookie(
|
|
|
49
43
|
export async function deleteCookie(
|
|
50
44
|
this: RemoteDebugger,
|
|
51
45
|
cookieName: string,
|
|
52
|
-
url: string
|
|
46
|
+
url: string,
|
|
53
47
|
): Promise<any> {
|
|
54
48
|
this.log.debug(`Deleting cookie '${cookieName}' on '${url}'`);
|
|
55
49
|
return await this.requireRpcClient().send('Page.deleteCookie', {
|
package/lib/mixins/events.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from '
|
|
4
|
-
import type { RemoteDebugger } from '../remote-debugger';
|
|
5
|
-
import type { EventListener } from '../types';
|
|
1
|
+
import {getClientEventListeners} from './property-accessors';
|
|
2
|
+
import type {RemoteDebugger} from '../remote-debugger';
|
|
3
|
+
import type {EventListener} from '../types';
|
|
6
4
|
|
|
7
5
|
// event emitted publically
|
|
8
6
|
export const events = {
|
|
@@ -21,7 +19,7 @@ export const events = {
|
|
|
21
19
|
export function addClientEventListener(
|
|
22
20
|
this: RemoteDebugger,
|
|
23
21
|
eventName: string,
|
|
24
|
-
listener: EventListener
|
|
22
|
+
listener: EventListener,
|
|
25
23
|
): void {
|
|
26
24
|
getClientEventListeners(this)[eventName] ??= [];
|
|
27
25
|
getClientEventListeners(this)[eventName].push(listener);
|
|
@@ -34,11 +32,8 @@ export function addClientEventListener(
|
|
|
34
32
|
*
|
|
35
33
|
* @param eventName - The name of the event to stop listening for.
|
|
36
34
|
*/
|
|
37
|
-
export function removeClientEventListener(
|
|
38
|
-
this
|
|
39
|
-
eventName: string
|
|
40
|
-
): void {
|
|
41
|
-
for (const listener of (getClientEventListeners(this)[eventName] || [])) {
|
|
35
|
+
export function removeClientEventListener(this: RemoteDebugger, eventName: string): void {
|
|
36
|
+
for (const listener of getClientEventListeners(this)[eventName] || []) {
|
|
42
37
|
this.requireRpcClient().off(eventName, listener);
|
|
43
38
|
}
|
|
44
39
|
}
|
|
@@ -49,10 +44,7 @@ export function removeClientEventListener(
|
|
|
49
44
|
*
|
|
50
45
|
* @param listener - The event listener function to call when console messages are received.
|
|
51
46
|
*/
|
|
52
|
-
export function startConsole(
|
|
53
|
-
this: RemoteDebugger,
|
|
54
|
-
listener: EventListener
|
|
55
|
-
): void {
|
|
47
|
+
export function startConsole(this: RemoteDebugger, listener: EventListener): void {
|
|
56
48
|
this.log.debug('Starting to listen for JavaScript console');
|
|
57
49
|
this.addClientEventListener('Console.messageAdded', listener);
|
|
58
50
|
this.addClientEventListener('Console.messageRepeatCountUpdated', listener);
|
|
@@ -74,10 +66,7 @@ export function stopConsole(this: RemoteDebugger): void {
|
|
|
74
66
|
*
|
|
75
67
|
* @param listener - The event listener function to call when network events are received.
|
|
76
68
|
*/
|
|
77
|
-
export function startNetwork(
|
|
78
|
-
this: RemoteDebugger,
|
|
79
|
-
listener: EventListener
|
|
80
|
-
): void {
|
|
69
|
+
export function startNetwork(this: RemoteDebugger, listener: EventListener): void {
|
|
81
70
|
this.log.debug('Starting to listen for network events');
|
|
82
71
|
this.addClientEventListener('NetworkEvent', listener);
|
|
83
72
|
}
|
package/lib/mixins/execute.ts
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {errors} from '@appium/base-driver';
|
|
2
2
|
import {
|
|
3
3
|
checkParams,
|
|
4
4
|
simpleStringify,
|
|
5
5
|
convertJavascriptEvaluationResult,
|
|
6
6
|
RESPONSE_LOG_LENGTH,
|
|
7
7
|
} from '../utils';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
8
|
+
import {getScriptForAtom} from '../atoms';
|
|
9
|
+
import {util, timing} from '@appium/support';
|
|
10
|
+
import {retryInterval} from 'asyncbox';
|
|
11
11
|
import _ from 'lodash';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
getGarbageCollectOnExecute,
|
|
16
|
-
} from './property-accessors';
|
|
17
|
-
import type { RemoteDebugger } from '../remote-debugger';
|
|
18
|
-
import type { AppIdKey, PageIdKey } from '../types';
|
|
12
|
+
import {getAppIdKey, getPageIdKey, getGarbageCollectOnExecute} from './property-accessors';
|
|
13
|
+
import type {RemoteDebugger} from '../remote-debugger';
|
|
14
|
+
import type {AppIdKey, PageIdKey} from '../types';
|
|
19
15
|
|
|
20
16
|
/* How many milliseconds to wait for webkit to return a response before timing out */
|
|
21
17
|
const RPC_RESPONSE_TIMEOUT_MS = 5000;
|
|
@@ -33,14 +29,16 @@ export async function executeAtom(
|
|
|
33
29
|
this: RemoteDebugger,
|
|
34
30
|
atom: string,
|
|
35
31
|
args: any[] = [],
|
|
36
|
-
frames: string[] = []
|
|
32
|
+
frames: string[] = [],
|
|
37
33
|
): Promise<any> {
|
|
38
34
|
this.log.debug(`Executing atom '${atom}' with 'args=${JSON.stringify(args)}; frames=${frames}'`);
|
|
39
35
|
const script = await getScriptForAtom(atom, args, frames);
|
|
40
36
|
const value = await this.execute(script);
|
|
41
|
-
this.log.debug(
|
|
42
|
-
|
|
43
|
-
|
|
37
|
+
this.log.debug(
|
|
38
|
+
`Received result for atom '${atom}' execution: ${_.truncate(simpleStringify(value), {
|
|
39
|
+
length: RESPONSE_LOG_LENGTH,
|
|
40
|
+
})}`,
|
|
41
|
+
);
|
|
44
42
|
return value;
|
|
45
43
|
}
|
|
46
44
|
|
|
@@ -59,20 +57,26 @@ export async function executeAtomAsync(
|
|
|
59
57
|
this: RemoteDebugger,
|
|
60
58
|
atom: string,
|
|
61
59
|
args: any[] = [],
|
|
62
|
-
frames: string[] = []
|
|
60
|
+
frames: string[] = [],
|
|
63
61
|
): Promise<any> {
|
|
64
62
|
// helper to send directly to the web inspector
|
|
65
|
-
const evaluate = async (method: string, opts: any) =>
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const evaluate = async (method: string, opts: any) =>
|
|
64
|
+
await this.requireRpcClient(true).send(
|
|
65
|
+
method,
|
|
66
|
+
Object.assign(
|
|
67
|
+
{
|
|
68
|
+
appIdKey: getAppIdKey(this),
|
|
69
|
+
pageIdKey: getPageIdKey(this),
|
|
70
|
+
returnByValue: false,
|
|
71
|
+
},
|
|
72
|
+
opts,
|
|
73
|
+
),
|
|
74
|
+
);
|
|
70
75
|
|
|
71
76
|
// first create a Promise on the page, saving the resolve/reject functions
|
|
72
77
|
// as properties
|
|
73
78
|
const promiseName = `appiumAsyncExecutePromise${util.uuidV4().replace(/-/g, '')}`;
|
|
74
|
-
const script =
|
|
75
|
-
`var res, rej;
|
|
79
|
+
const script = `var res, rej;
|
|
76
80
|
window.${promiseName} = new Promise(function (resolve, reject) {
|
|
77
81
|
res = resolve;
|
|
78
82
|
rej = reject;
|
|
@@ -86,8 +90,7 @@ export async function executeAtomAsync(
|
|
|
86
90
|
const promiseObjectId = obj.result.objectId;
|
|
87
91
|
|
|
88
92
|
// execute the atom, calling back to the resolve function
|
|
89
|
-
const asyncCallBack =
|
|
90
|
-
`function (res) {
|
|
93
|
+
const asyncCallBack = `function (res) {
|
|
91
94
|
window.${promiseName}.resolve(res);
|
|
92
95
|
window.${promiseName}Value = res;
|
|
93
96
|
}`;
|
|
@@ -109,7 +112,7 @@ export async function executeAtomAsync(
|
|
|
109
112
|
}
|
|
110
113
|
// awaitPromise is not always available, so simulate it with poll
|
|
111
114
|
const retryWait = 100;
|
|
112
|
-
const timeout =
|
|
115
|
+
const timeout = args.length >= 3 ? args[2] : RPC_RESPONSE_TIMEOUT_MS;
|
|
113
116
|
// if the timeout math turns up 0 retries, make sure it happens once
|
|
114
117
|
const retries = parseInt(`${timeout / retryWait}`, 10) || 1;
|
|
115
118
|
const timer = new timing.Timer().start();
|
|
@@ -130,14 +133,18 @@ export async function executeAtomAsync(
|
|
|
130
133
|
});
|
|
131
134
|
}
|
|
132
135
|
// throw a TimeoutError, or else it needs to be caught and re-thrown
|
|
133
|
-
throw new errors.TimeoutError(
|
|
134
|
-
|
|
136
|
+
throw new errors.TimeoutError(
|
|
137
|
+
`Timed out waiting for asynchronous script ` +
|
|
138
|
+
`result after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms'));`,
|
|
139
|
+
);
|
|
135
140
|
});
|
|
136
141
|
} finally {
|
|
137
142
|
try {
|
|
138
143
|
// try to get rid of the promise
|
|
139
144
|
await this.executeAtom(
|
|
140
|
-
'execute_script',
|
|
145
|
+
'execute_script',
|
|
146
|
+
[`delete window.${promiseName};`, [null, null], subcommandTimeout],
|
|
147
|
+
frames,
|
|
141
148
|
);
|
|
142
149
|
} catch {}
|
|
143
150
|
}
|
|
@@ -154,7 +161,11 @@ export async function executeAtomAsync(
|
|
|
154
161
|
* converted to a usable format.
|
|
155
162
|
*/
|
|
156
163
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
157
|
-
export async function execute(
|
|
164
|
+
export async function execute(
|
|
165
|
+
this: RemoteDebugger,
|
|
166
|
+
command: string,
|
|
167
|
+
override?: boolean,
|
|
168
|
+
): Promise<any> {
|
|
158
169
|
const {appIdKey, pageIdKey} = checkParams({
|
|
159
170
|
appIdKey: getAppIdKey(this),
|
|
160
171
|
pageIdKey: getPageIdKey(this),
|
|
@@ -165,10 +176,7 @@ export async function execute(this: RemoteDebugger, command: string, override?:
|
|
|
165
176
|
}
|
|
166
177
|
|
|
167
178
|
const rpcClient = this.requireRpcClient(true);
|
|
168
|
-
await rpcClient.waitForPage(
|
|
169
|
-
appIdKey as AppIdKey,
|
|
170
|
-
pageIdKey as PageIdKey
|
|
171
|
-
);
|
|
179
|
+
await rpcClient.waitForPage(appIdKey as AppIdKey, pageIdKey as PageIdKey);
|
|
172
180
|
this.log.debug(`Sending javascript command: '${_.truncate(command, {length: 50})}'`);
|
|
173
181
|
const res = await rpcClient.send('Runtime.evaluate', {
|
|
174
182
|
expression: command,
|
|
@@ -193,7 +201,7 @@ export async function callFunction(
|
|
|
193
201
|
this: RemoteDebugger,
|
|
194
202
|
objectId: string,
|
|
195
203
|
fn: string,
|
|
196
|
-
args?: any[]
|
|
204
|
+
args?: any[],
|
|
197
205
|
): Promise<any> {
|
|
198
206
|
const {appIdKey, pageIdKey} = checkParams({
|
|
199
207
|
appIdKey: getAppIdKey(this),
|