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
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
import defaultLog from './logger';
|
|
3
|
+
import { RpcClientSimulator } from './rpc';
|
|
4
|
+
import { getModuleProperties } from './utils';
|
|
5
|
+
import * as connectMixins from './mixins/connect';
|
|
6
|
+
import * as executeMixins from './mixins/execute';
|
|
7
|
+
import * as messageHandlerMixins from './mixins/message-handlers';
|
|
8
|
+
import * as navigationMixins from './mixins/navigate';
|
|
9
|
+
import * as cookieMixins from './mixins/cookies';
|
|
10
|
+
import * as screenshotMixins from './mixins/screenshot';
|
|
11
|
+
import * as eventMixins from './mixins/events';
|
|
12
|
+
import * as miscellaneousMixins from './mixins/misc';
|
|
13
|
+
import _ from 'lodash';
|
|
14
|
+
import type {
|
|
15
|
+
RemoteDebuggerOptions,
|
|
16
|
+
AppDict,
|
|
17
|
+
EventListener
|
|
18
|
+
} from './types';
|
|
19
|
+
import type { AppiumLogger, StringRecord } from '@appium/types';
|
|
20
|
+
import type { RpcClient } from './rpc/rpc-client';
|
|
21
|
+
import type B from 'bluebird';
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export const REMOTE_DEBUGGER_PORT = 27753;
|
|
25
|
+
const PAGE_READY_TIMEOUT_MS = 5000;
|
|
26
|
+
const { version: MODULE_VERSION } = getModuleProperties();
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export class RemoteDebugger extends EventEmitter {
|
|
30
|
+
protected _skippedApps: string[];
|
|
31
|
+
protected _clientEventListeners: StringRecord<EventListener[]>;
|
|
32
|
+
protected _appDict: AppDict;
|
|
33
|
+
protected _appIdKey: string | null | undefined;
|
|
34
|
+
protected _pageIdKey: string | number | null | undefined;
|
|
35
|
+
protected _connectedDrivers: StringRecord[] | undefined;
|
|
36
|
+
protected _currentState: string | undefined;
|
|
37
|
+
protected _pageLoadDelay: B<void> | undefined;
|
|
38
|
+
protected _rpcClient: RpcClient | null;
|
|
39
|
+
protected _pageLoading: boolean;
|
|
40
|
+
protected _navigatingToPage: boolean;
|
|
41
|
+
protected _allowNavigationWithoutReload: boolean;
|
|
42
|
+
protected _pageLoadMs: number | undefined;
|
|
43
|
+
protected readonly _pageLoadStrategy: string | undefined;
|
|
44
|
+
protected readonly _log: AppiumLogger;
|
|
45
|
+
protected readonly _bundleId: string | undefined;
|
|
46
|
+
protected readonly _additionalBundleIds: string[] | undefined;
|
|
47
|
+
protected readonly _platformVersion: string | undefined;
|
|
48
|
+
protected readonly _isSafari: boolean;
|
|
49
|
+
protected readonly _includeSafari: boolean;
|
|
50
|
+
protected readonly _useNewSafari: boolean;
|
|
51
|
+
protected readonly _garbageCollectOnExecute: boolean;
|
|
52
|
+
protected readonly _host: string | undefined;
|
|
53
|
+
protected readonly _port: number | undefined;
|
|
54
|
+
protected readonly _socketPath: string | undefined;
|
|
55
|
+
protected readonly _remoteDebugProxy: any | undefined;
|
|
56
|
+
protected readonly _pageReadyTimeout: number;
|
|
57
|
+
protected readonly _logAllCommunication: boolean;
|
|
58
|
+
protected readonly _logAllCommunicationHexDump: boolean;
|
|
59
|
+
protected readonly _socketChunkSize: number | undefined;
|
|
60
|
+
protected readonly _webInspectorMaxFrameLength: number | undefined;
|
|
61
|
+
protected readonly _fullPageInitialization: boolean | undefined;
|
|
62
|
+
|
|
63
|
+
// events
|
|
64
|
+
static readonly EVENT_PAGE_CHANGE: string;
|
|
65
|
+
static readonly EVENT_DISCONNECT: string;
|
|
66
|
+
static readonly EVENT_FRAMES_DETACHED: string;
|
|
67
|
+
|
|
68
|
+
// methods
|
|
69
|
+
setConnectionKey = connectMixins.setConnectionKey;
|
|
70
|
+
disconnect = connectMixins.disconnect;
|
|
71
|
+
checkPageIsReady = navigationMixins.checkPageIsReady;
|
|
72
|
+
cancelPageLoad = navigationMixins.cancelPageLoad;
|
|
73
|
+
waitForDom = navigationMixins.waitForDom;
|
|
74
|
+
execute = executeMixins.execute;
|
|
75
|
+
executeAtom = executeMixins.executeAtom;
|
|
76
|
+
executeAtomAsync = executeMixins.executeAtomAsync;
|
|
77
|
+
isPageLoadingCompleted = navigationMixins.isPageLoadingCompleted;
|
|
78
|
+
selectApp = connectMixins.selectApp;
|
|
79
|
+
connect = connectMixins.connect;
|
|
80
|
+
selectPage = connectMixins.selectPage;
|
|
81
|
+
navToUrl = navigationMixins.navToUrl;
|
|
82
|
+
getCookies = cookieMixins.getCookies;
|
|
83
|
+
setCookie = cookieMixins.setCookie;
|
|
84
|
+
deleteCookie = cookieMixins.deleteCookie;
|
|
85
|
+
captureScreenshot = screenshotMixins.captureScreenshot;
|
|
86
|
+
addClientEventListener = eventMixins.addClientEventListener;
|
|
87
|
+
removeClientEventListener = eventMixins.removeClientEventListener;
|
|
88
|
+
startConsole = eventMixins.startConsole;
|
|
89
|
+
stopConsole = eventMixins.stopConsole;
|
|
90
|
+
startNetwork = eventMixins.startNetwork;
|
|
91
|
+
stopNetwork = eventMixins.stopNetwork;
|
|
92
|
+
launchSafari = miscellaneousMixins.launchSafari;
|
|
93
|
+
startTimeline = miscellaneousMixins.startTimeline;
|
|
94
|
+
stopTimeline = miscellaneousMixins.stopTimeline;
|
|
95
|
+
overrideUserAgent = miscellaneousMixins.overrideUserAgent;
|
|
96
|
+
garbageCollect = miscellaneousMixins.garbageCollect;
|
|
97
|
+
|
|
98
|
+
// Callbacks
|
|
99
|
+
onPageChange = messageHandlerMixins.onPageChange;
|
|
100
|
+
onConnectedApplicationList = messageHandlerMixins.onConnectedApplicationList;
|
|
101
|
+
onAppConnect = messageHandlerMixins.onAppConnect;
|
|
102
|
+
onAppDisconnect = messageHandlerMixins.onAppDisconnect;
|
|
103
|
+
onAppUpdate = messageHandlerMixins.onAppUpdate;
|
|
104
|
+
onConnectedDriverList = messageHandlerMixins.onConnectedDriverList;
|
|
105
|
+
onCurrentState = messageHandlerMixins.onCurrentState;
|
|
106
|
+
frameDetached = navigationMixins.frameDetached;
|
|
107
|
+
|
|
108
|
+
constructor (opts: RemoteDebuggerOptions = {}) {
|
|
109
|
+
super();
|
|
110
|
+
|
|
111
|
+
this._log = opts.log ?? defaultLog;
|
|
112
|
+
this.log.info(`Remote Debugger version ${MODULE_VERSION}`);
|
|
113
|
+
|
|
114
|
+
const {
|
|
115
|
+
bundleId,
|
|
116
|
+
additionalBundleIds = [],
|
|
117
|
+
platformVersion,
|
|
118
|
+
isSafari = true,
|
|
119
|
+
includeSafari = false,
|
|
120
|
+
useNewSafari = false,
|
|
121
|
+
pageLoadMs,
|
|
122
|
+
host,
|
|
123
|
+
port = REMOTE_DEBUGGER_PORT,
|
|
124
|
+
socketPath,
|
|
125
|
+
pageReadyTimeout = PAGE_READY_TIMEOUT_MS,
|
|
126
|
+
remoteDebugProxy,
|
|
127
|
+
garbageCollectOnExecute = false,
|
|
128
|
+
logFullResponse = false,
|
|
129
|
+
logAllCommunication = false,
|
|
130
|
+
logAllCommunicationHexDump = false,
|
|
131
|
+
webInspectorMaxFrameLength,
|
|
132
|
+
socketChunkSize,
|
|
133
|
+
fullPageInitialization,
|
|
134
|
+
pageLoadStrategy,
|
|
135
|
+
} = opts;
|
|
136
|
+
|
|
137
|
+
this._bundleId = bundleId;
|
|
138
|
+
this._additionalBundleIds = additionalBundleIds;
|
|
139
|
+
this._platformVersion = platformVersion;
|
|
140
|
+
this._isSafari = isSafari;
|
|
141
|
+
this._includeSafari = includeSafari;
|
|
142
|
+
this._useNewSafari = useNewSafari;
|
|
143
|
+
this._pageLoadMs = pageLoadMs;
|
|
144
|
+
this._allowNavigationWithoutReload = false;
|
|
145
|
+
this.log.debug(`useNewSafari --> ${this._useNewSafari}`);
|
|
146
|
+
|
|
147
|
+
this._garbageCollectOnExecute = garbageCollectOnExecute;
|
|
148
|
+
|
|
149
|
+
this._host = host;
|
|
150
|
+
this._port = port;
|
|
151
|
+
this._socketPath = socketPath;
|
|
152
|
+
this._remoteDebugProxy = remoteDebugProxy;
|
|
153
|
+
this._pageReadyTimeout = pageReadyTimeout;
|
|
154
|
+
|
|
155
|
+
this._logAllCommunication = _.isNil(logAllCommunication) ? !!logFullResponse : !!logAllCommunication;
|
|
156
|
+
this._logAllCommunicationHexDump = logAllCommunicationHexDump;
|
|
157
|
+
this._socketChunkSize = socketChunkSize;
|
|
158
|
+
|
|
159
|
+
if (_.isInteger(webInspectorMaxFrameLength)) {
|
|
160
|
+
this._webInspectorMaxFrameLength = webInspectorMaxFrameLength;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
this._fullPageInitialization = fullPageInitialization;
|
|
164
|
+
|
|
165
|
+
this._pageLoadStrategy = pageLoadStrategy;
|
|
166
|
+
this._skippedApps = [];
|
|
167
|
+
|
|
168
|
+
this.setup();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
get log(): AppiumLogger {
|
|
172
|
+
return this._log;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
requireRpcClient(checkConnected: boolean = false): RpcClient {
|
|
176
|
+
if (!this._rpcClient) {
|
|
177
|
+
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
178
|
+
}
|
|
179
|
+
if (checkConnected && !this._rpcClient.isConnected) {
|
|
180
|
+
throw new Error('Remote debugger is not connected');
|
|
181
|
+
}
|
|
182
|
+
return this._rpcClient;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
setup (): void {
|
|
186
|
+
// app handling configuration
|
|
187
|
+
this._appDict = {};
|
|
188
|
+
this._appIdKey = null;
|
|
189
|
+
this._pageIdKey = null;
|
|
190
|
+
this._pageLoading = false;
|
|
191
|
+
this._navigatingToPage = false;
|
|
192
|
+
this._currentState = undefined;
|
|
193
|
+
this._connectedDrivers = undefined;
|
|
194
|
+
this._pageLoadDelay = undefined;
|
|
195
|
+
|
|
196
|
+
this._rpcClient = null;
|
|
197
|
+
this._clientEventListeners = {};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
teardown (): void {
|
|
201
|
+
this.log.debug('Cleaning up listeners');
|
|
202
|
+
|
|
203
|
+
this._appDict = {};
|
|
204
|
+
this._appIdKey = null;
|
|
205
|
+
this._pageIdKey = null;
|
|
206
|
+
this._pageLoading = false;
|
|
207
|
+
|
|
208
|
+
this._rpcClient = null;
|
|
209
|
+
|
|
210
|
+
for (const evt of [
|
|
211
|
+
RemoteDebugger.EVENT_DISCONNECT,
|
|
212
|
+
RemoteDebugger.EVENT_PAGE_CHANGE,
|
|
213
|
+
RemoteDebugger.EVENT_FRAMES_DETACHED,
|
|
214
|
+
]) {
|
|
215
|
+
this.removeAllListeners(evt);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
initRpcClient (): void {
|
|
220
|
+
this._rpcClient = new RpcClientSimulator({
|
|
221
|
+
bundleId: this._bundleId,
|
|
222
|
+
platformVersion: this._platformVersion,
|
|
223
|
+
isSafari: this._isSafari,
|
|
224
|
+
host: this._host,
|
|
225
|
+
port: this._port,
|
|
226
|
+
socketPath: this._socketPath,
|
|
227
|
+
messageProxy: this._remoteDebugProxy,
|
|
228
|
+
logAllCommunication: this._logAllCommunication,
|
|
229
|
+
logAllCommunicationHexDump: this._logAllCommunicationHexDump,
|
|
230
|
+
fullPageInitialization: this._fullPageInitialization,
|
|
231
|
+
webInspectorMaxFrameLength: this._webInspectorMaxFrameLength,
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
get isConnected (): boolean {
|
|
236
|
+
return !!this._rpcClient?.isConnected;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
set allowNavigationWithoutReload (allow: boolean) {
|
|
240
|
+
this._allowNavigationWithoutReload = allow;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
get allowNavigationWithoutReload (): boolean {
|
|
244
|
+
return !!this._allowNavigationWithoutReload;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
get currentState (): string | undefined {
|
|
248
|
+
return this._currentState;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
get connectedDrivers (): StringRecord[] | undefined {
|
|
252
|
+
return this._connectedDrivers;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
get pageLoadMs (): number {
|
|
256
|
+
return this._pageLoadMs ?? navigationMixins.DEFAULT_PAGE_READINESS_TIMEOUT_MS;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
set pageLoadMs (value: number) {
|
|
260
|
+
this._pageLoadMs = value;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
for (const [name, event] of _.toPairs(eventMixins.events)) {
|
|
265
|
+
RemoteDebugger[name] = event;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
export default RemoteDebugger;
|
package/lib/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { StringRecord } from '@appium/types';
|
|
1
|
+
import type { StringRecord, AppiumLogger } from '@appium/types';
|
|
2
2
|
import type B from 'bluebird';
|
|
3
3
|
|
|
4
4
|
export interface DeferredPromise {
|
|
@@ -37,3 +37,46 @@ export interface Page {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export type AppDict = StringRecord<AppInfo>;
|
|
40
|
+
|
|
41
|
+
export type EventListener = (event: StringRecord) => any;
|
|
42
|
+
|
|
43
|
+
export interface RemoteDebuggerOptions {
|
|
44
|
+
/** id of the app being connected to */
|
|
45
|
+
bundleId?: string;
|
|
46
|
+
/** array of possible bundle ids that the inspector could return */
|
|
47
|
+
additionalBundleIds?: string[];
|
|
48
|
+
/** version of iOS */
|
|
49
|
+
platformVersion?: string;
|
|
50
|
+
isSafari?: boolean;
|
|
51
|
+
includeSafari?: boolean;
|
|
52
|
+
/** for web inspector, whether this is a new Safari instance */
|
|
53
|
+
useNewSafari?: boolean;
|
|
54
|
+
/** the time, in ms, that should be waited for page loading */
|
|
55
|
+
pageLoadMs?: number;
|
|
56
|
+
/** the remote debugger's host address */
|
|
57
|
+
host?: string;
|
|
58
|
+
/** the remote debugger port through which to communicate */
|
|
59
|
+
port?: number;
|
|
60
|
+
socketPath?: string;
|
|
61
|
+
pageReadyTimeout?: number;
|
|
62
|
+
remoteDebugProxy?: string;
|
|
63
|
+
garbageCollectOnExecute?: boolean;
|
|
64
|
+
logFullResponse?: boolean;
|
|
65
|
+
/** log plists sent and received from Web Inspector */
|
|
66
|
+
logAllCommunication?: boolean;
|
|
67
|
+
/** log communication from Web Inspector as hex dump */
|
|
68
|
+
logAllCommunicationHexDump?: boolean;
|
|
69
|
+
/** The maximum size in bytes of a single data frame in the device communication protocol */
|
|
70
|
+
webInspectorMaxFrameLength?: number;
|
|
71
|
+
/** size, in bytes, of chunks of data sent to Web Inspector (real device only) */
|
|
72
|
+
socketChunkSize?: number;
|
|
73
|
+
fullPageInitialization?: boolean;
|
|
74
|
+
pageLoadStrategy?: string;
|
|
75
|
+
log?: AppiumLogger;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
interface RemoteDebuggerRealDeviceSpecificOptions {
|
|
79
|
+
udid: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export type RemoteDebuggerRealDeviceOptions = RemoteDebuggerRealDeviceSpecificOptions & RemoteDebuggerOptions;
|
package/package.json
CHANGED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import RemoteDebugger from './remote-debugger';
|
|
2
|
-
import { RpcClientRealDevice } from './rpc';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* @typedef {Object} RemoteDebuggerRealDeviceOptions
|
|
6
|
-
* @property {string} udid Real device UDID
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export default class RemoteDebuggerRealDevice extends RemoteDebugger {
|
|
10
|
-
/** @type {string} */
|
|
11
|
-
udid;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {RemoteDebuggerRealDeviceOptions & import('./remote-debugger').RemoteDebuggerOptions} opts
|
|
15
|
-
*/
|
|
16
|
-
constructor (opts) {
|
|
17
|
-
super(opts);
|
|
18
|
-
|
|
19
|
-
this.udid = opts.udid;
|
|
20
|
-
|
|
21
|
-
this._skippedApps = ['lockdownd'];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @override
|
|
26
|
-
*/
|
|
27
|
-
initRpcClient () {
|
|
28
|
-
this.rpcClient = new RpcClientRealDevice({
|
|
29
|
-
bundleId: this.bundleId,
|
|
30
|
-
platformVersion: this.platformVersion,
|
|
31
|
-
isSafari: this.isSafari,
|
|
32
|
-
logAllCommunication: this.logAllCommunication,
|
|
33
|
-
logAllCommunicationHexDump: this.logAllCommunicationHexDump,
|
|
34
|
-
socketChunkSize: this.socketChunkSize,
|
|
35
|
-
webInspectorMaxFrameLength: this.webInspectorMaxFrameLength,
|
|
36
|
-
udid: this.udid,
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
package/lib/remote-debugger.js
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
import defaultLog from './logger';
|
|
3
|
-
import { RpcClientSimulator } from './rpc';
|
|
4
|
-
import { getModuleProperties } from './utils';
|
|
5
|
-
import * as connectMixins from './mixins/connect';
|
|
6
|
-
import * as executeMixins from './mixins/execute';
|
|
7
|
-
import * as messageHandlerMixins from './mixins/message-handlers';
|
|
8
|
-
import * as navigationMixins from './mixins/navigate';
|
|
9
|
-
import * as cookieMixins from './mixins/cookies';
|
|
10
|
-
import * as screenshotMixins from './mixins/screenshot';
|
|
11
|
-
import * as eventMixins from './mixins/events';
|
|
12
|
-
import * as miscellaneousMixins from './mixins/misc';
|
|
13
|
-
import _ from 'lodash';
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const REMOTE_DEBUGGER_PORT = 27753;
|
|
17
|
-
/* How many milliseconds to wait for webkit to return a response before timing out */
|
|
18
|
-
export const RPC_RESPONSE_TIMEOUT_MS = 5000;
|
|
19
|
-
const PAGE_READY_TIMEOUT_MS = 5000;
|
|
20
|
-
const { version: MODULE_VERSION } = getModuleProperties();
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export class RemoteDebugger extends EventEmitter {
|
|
24
|
-
// properties
|
|
25
|
-
/** @type {string[]|undefined} */
|
|
26
|
-
_skippedApps;
|
|
27
|
-
/** @type {import('@appium/types').StringRecord<Function[]>} */
|
|
28
|
-
_clientEventListeners;
|
|
29
|
-
/** @type {import('./types').AppDict} */
|
|
30
|
-
appDict;
|
|
31
|
-
/** @type {string|null|undefined} */
|
|
32
|
-
appIdKey;
|
|
33
|
-
/** @type {string|number|null|undefined} */
|
|
34
|
-
pageIdKey;
|
|
35
|
-
/** @type {Record<string, any>[]|undefined} */
|
|
36
|
-
connectedDrivers;
|
|
37
|
-
/** @type {Record<string, any>[]|undefined} */
|
|
38
|
-
currentState;
|
|
39
|
-
/** @type {boolean|undefined} */
|
|
40
|
-
connected;
|
|
41
|
-
/** @type {import('bluebird')<void>} */
|
|
42
|
-
pageLoadDelay;
|
|
43
|
-
/** @type {import('bluebird')<void>} */
|
|
44
|
-
navigationDelay;
|
|
45
|
-
/** @type {import('./rpc/rpc-client').RpcClient?} */
|
|
46
|
-
rpcClient;
|
|
47
|
-
/** @type {string|undefined} */
|
|
48
|
-
pageLoadStrategy;
|
|
49
|
-
/** @type {import('@appium/types').AppiumLogger} */
|
|
50
|
-
_log;
|
|
51
|
-
|
|
52
|
-
// events
|
|
53
|
-
/** @type {string} */
|
|
54
|
-
static EVENT_PAGE_CHANGE;
|
|
55
|
-
/** @type {string} */
|
|
56
|
-
static EVENT_DISCONNECT;
|
|
57
|
-
/** @type {string} */
|
|
58
|
-
static EVENT_FRAMES_DETACHED;
|
|
59
|
-
|
|
60
|
-
// methods
|
|
61
|
-
setConnectionKey = connectMixins.setConnectionKey;
|
|
62
|
-
disconnect = connectMixins.disconnect;
|
|
63
|
-
searchForApp = connectMixins.searchForApp;
|
|
64
|
-
searchForPage = connectMixins.searchForPage;
|
|
65
|
-
checkPageIsReady = navigationMixins.checkPageIsReady;
|
|
66
|
-
cancelPageLoad = navigationMixins.cancelPageLoad;
|
|
67
|
-
waitForDom = navigationMixins.waitForDom;
|
|
68
|
-
execute = executeMixins.execute;
|
|
69
|
-
executeAtom = executeMixins.executeAtom;
|
|
70
|
-
executeAtomAsync = executeMixins.executeAtomAsync;
|
|
71
|
-
isPageLoadingCompleted = navigationMixins.isPageLoadingCompleted;
|
|
72
|
-
selectApp = connectMixins.selectApp;
|
|
73
|
-
connect = connectMixins.connect;
|
|
74
|
-
selectPage = connectMixins.selectPage;
|
|
75
|
-
navToUrl = navigationMixins.navToUrl;
|
|
76
|
-
getCookies = cookieMixins.getCookies;
|
|
77
|
-
setCookie = cookieMixins.setCookie;
|
|
78
|
-
deleteCookie = cookieMixins.deleteCookie;
|
|
79
|
-
captureScreenshot = screenshotMixins.captureScreenshot;
|
|
80
|
-
addClientEventListener = eventMixins.addClientEventListener;
|
|
81
|
-
removeClientEventListener = eventMixins.removeClientEventListener;
|
|
82
|
-
launchSafari = miscellaneousMixins.launchSafari;
|
|
83
|
-
startTimeline = miscellaneousMixins.startTimeline;
|
|
84
|
-
stopTimeline = miscellaneousMixins.stopTimeline;
|
|
85
|
-
startConsole = miscellaneousMixins.startConsole;
|
|
86
|
-
stopConsole = miscellaneousMixins.stopConsole;
|
|
87
|
-
startNetwork = miscellaneousMixins.startNetwork;
|
|
88
|
-
stopNetwork = miscellaneousMixins.stopNetwork;
|
|
89
|
-
overrideUserAgent = miscellaneousMixins.overrideUserAgent;
|
|
90
|
-
garbageCollect = miscellaneousMixins.garbageCollect;
|
|
91
|
-
|
|
92
|
-
// Callbacks
|
|
93
|
-
onPageChange = messageHandlerMixins.onPageChange;
|
|
94
|
-
onConnectedApplicationList = messageHandlerMixins.onConnectedApplicationList;
|
|
95
|
-
onAppConnect = messageHandlerMixins.onAppConnect;
|
|
96
|
-
onAppDisconnect = messageHandlerMixins.onAppDisconnect;
|
|
97
|
-
onAppUpdate = messageHandlerMixins.onAppUpdate;
|
|
98
|
-
onConnectedDriverList = messageHandlerMixins.onConnectedDriverList;
|
|
99
|
-
onCurrentState = messageHandlerMixins.onCurrentState;
|
|
100
|
-
frameDetached = navigationMixins.frameDetached;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* @param {RemoteDebuggerOptions} opts
|
|
104
|
-
*/
|
|
105
|
-
constructor (opts = {}) {
|
|
106
|
-
super();
|
|
107
|
-
|
|
108
|
-
// @ts-ignore This is OK
|
|
109
|
-
this._log = opts.log ?? defaultLog;
|
|
110
|
-
this.log.info(`Remote Debugger version ${MODULE_VERSION}`);
|
|
111
|
-
|
|
112
|
-
const {
|
|
113
|
-
bundleId,
|
|
114
|
-
additionalBundleIds = [],
|
|
115
|
-
platformVersion,
|
|
116
|
-
isSafari = true,
|
|
117
|
-
includeSafari = false,
|
|
118
|
-
useNewSafari = false,
|
|
119
|
-
pageLoadMs,
|
|
120
|
-
host,
|
|
121
|
-
port = REMOTE_DEBUGGER_PORT,
|
|
122
|
-
socketPath,
|
|
123
|
-
pageReadyTimeout = PAGE_READY_TIMEOUT_MS,
|
|
124
|
-
remoteDebugProxy,
|
|
125
|
-
garbageCollectOnExecute = false,
|
|
126
|
-
logFullResponse = false,
|
|
127
|
-
logAllCommunication = false,
|
|
128
|
-
logAllCommunicationHexDump = false,
|
|
129
|
-
webInspectorMaxFrameLength,
|
|
130
|
-
socketChunkSize,
|
|
131
|
-
fullPageInitialization,
|
|
132
|
-
pageLoadStrategy,
|
|
133
|
-
} = opts;
|
|
134
|
-
|
|
135
|
-
this.bundleId = bundleId;
|
|
136
|
-
this.additionalBundleIds = additionalBundleIds;
|
|
137
|
-
this.platformVersion = platformVersion;
|
|
138
|
-
this.isSafari = isSafari;
|
|
139
|
-
this.includeSafari = includeSafari;
|
|
140
|
-
this.useNewSafari = useNewSafari;
|
|
141
|
-
this.pageLoadMs = pageLoadMs;
|
|
142
|
-
this.log.debug(`useNewSafari --> ${this.useNewSafari}`);
|
|
143
|
-
|
|
144
|
-
this.garbageCollectOnExecute = garbageCollectOnExecute;
|
|
145
|
-
|
|
146
|
-
this.host = host;
|
|
147
|
-
this.port = port;
|
|
148
|
-
this.socketPath = socketPath;
|
|
149
|
-
this.remoteDebugProxy = remoteDebugProxy;
|
|
150
|
-
this.pageReadyTimeout = pageReadyTimeout;
|
|
151
|
-
|
|
152
|
-
this.logAllCommunication = _.isNil(logAllCommunication) ? !!logFullResponse : !!logAllCommunication;
|
|
153
|
-
this.logAllCommunicationHexDump = logAllCommunicationHexDump;
|
|
154
|
-
this.socketChunkSize = socketChunkSize;
|
|
155
|
-
|
|
156
|
-
if (_.isInteger(webInspectorMaxFrameLength)) {
|
|
157
|
-
this.webInspectorMaxFrameLength = webInspectorMaxFrameLength;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
this.fullPageInitialization = fullPageInitialization;
|
|
161
|
-
|
|
162
|
-
this.pageLoadStrategy = pageLoadStrategy;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* @returns {import('@appium/types').AppiumLogger}
|
|
167
|
-
*/
|
|
168
|
-
get log() {
|
|
169
|
-
return this._log;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* @param {boolean} [checkConnected=false]
|
|
174
|
-
* @returns {import('./rpc/rpc-client').RpcClient}
|
|
175
|
-
*/
|
|
176
|
-
requireRpcClient(checkConnected = false) {
|
|
177
|
-
if (!this.rpcClient) {
|
|
178
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
179
|
-
}
|
|
180
|
-
if (checkConnected && !this.rpcClient.isConnected) {
|
|
181
|
-
throw new Error('Remote debugger is not connected');
|
|
182
|
-
}
|
|
183
|
-
return this.rpcClient;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* @returns {void}
|
|
188
|
-
*/
|
|
189
|
-
setup () {
|
|
190
|
-
// app handling configuration
|
|
191
|
-
this.appDict = {};
|
|
192
|
-
this.appIdKey = null;
|
|
193
|
-
this.pageIdKey = null;
|
|
194
|
-
this.pageLoading = false;
|
|
195
|
-
this._navigatingToPage = false;
|
|
196
|
-
this.allowNavigationWithoutReload = false;
|
|
197
|
-
|
|
198
|
-
this.rpcClient = null;
|
|
199
|
-
this._clientEventListeners = {};
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* @returns {void}
|
|
204
|
-
*/
|
|
205
|
-
teardown () {
|
|
206
|
-
this.log.debug('Cleaning up listeners');
|
|
207
|
-
|
|
208
|
-
this.appDict = {};
|
|
209
|
-
this.appIdKey = null;
|
|
210
|
-
this.pageIdKey = null;
|
|
211
|
-
this.pageLoading = false;
|
|
212
|
-
|
|
213
|
-
this.rpcClient = null;
|
|
214
|
-
|
|
215
|
-
this.removeAllListeners(RemoteDebugger.EVENT_PAGE_CHANGE);
|
|
216
|
-
this.removeAllListeners(RemoteDebugger.EVENT_DISCONNECT);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* @returns {void}
|
|
221
|
-
*/
|
|
222
|
-
initRpcClient () {
|
|
223
|
-
this.rpcClient = new RpcClientSimulator({
|
|
224
|
-
bundleId: this.bundleId,
|
|
225
|
-
platformVersion: this.platformVersion,
|
|
226
|
-
isSafari: this.isSafari,
|
|
227
|
-
host: this.host,
|
|
228
|
-
port: this.port,
|
|
229
|
-
socketPath: this.socketPath,
|
|
230
|
-
messageProxy: this.remoteDebugProxy,
|
|
231
|
-
logAllCommunication: this.logAllCommunication,
|
|
232
|
-
logAllCommunicationHexDump: this.logAllCommunicationHexDump,
|
|
233
|
-
fullPageInitialization: this.fullPageInitialization,
|
|
234
|
-
webInspectorMaxFrameLength: this.webInspectorMaxFrameLength,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* @returns {boolean}
|
|
240
|
-
*/
|
|
241
|
-
get isConnected () {
|
|
242
|
-
return !!this.rpcClient?.isConnected;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* @param {boolean} allow
|
|
247
|
-
*/
|
|
248
|
-
set allowNavigationWithoutReload (allow) {
|
|
249
|
-
this._allowNavigationWithoutReload = allow;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* @returns {boolean}
|
|
254
|
-
*/
|
|
255
|
-
get allowNavigationWithoutReload () {
|
|
256
|
-
return !!this._allowNavigationWithoutReload;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* @returns {string[]}
|
|
261
|
-
*/
|
|
262
|
-
get skippedApps () {
|
|
263
|
-
return this._skippedApps ?? [];
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
for (const [name, event] of _.toPairs(eventMixins.events)) {
|
|
268
|
-
RemoteDebugger[name] = event;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export default RemoteDebugger;
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* @typedef {Object} RemoteDebuggerOptions
|
|
275
|
-
* @property {string} [bundleId] id of the app being connected to
|
|
276
|
-
* @property {string[]} [additionalBundleIds=[]] array of possible bundle
|
|
277
|
-
* ids that the inspector could return
|
|
278
|
-
* @property {string} [platformVersion] version of iOS
|
|
279
|
-
* @property {boolean} [isSafari=true]
|
|
280
|
-
* @property {boolean} [includeSafari=false]
|
|
281
|
-
* @property {boolean} [useNewSafari=false] for web inspector, whether this is a new Safari instance
|
|
282
|
-
* @property {number} [pageLoadMs] the time, in ms, that should be waited for page loading
|
|
283
|
-
* @property {string} [host] the remote debugger's host address
|
|
284
|
-
* @property {number} [port=REMOTE_DEBUGGER_PORT] the remote debugger port through which to communicate
|
|
285
|
-
* @property {string} [socketPath]
|
|
286
|
-
* @property {number} [pageReadyTimeout=PAGE_READY_TIMEOUT]
|
|
287
|
-
* @property {string} [remoteDebugProxy]
|
|
288
|
-
* @property {boolean} [garbageCollectOnExecute=false]
|
|
289
|
-
* @property {boolean} [logFullResponse=false]
|
|
290
|
-
* @property {boolean} [logAllCommunication=false] log plists sent and received from Web Inspector
|
|
291
|
-
* @property {boolean} [logAllCommunicationHexDump=false] log communication from Web Inspector as hex dump
|
|
292
|
-
* @property {number} [webInspectorMaxFrameLength] The maximum size in bytes of a single data
|
|
293
|
-
* frame in the device communication protocol
|
|
294
|
-
* @property {number} [socketChunkSize] size, in bytes, of chunks of data sent to
|
|
295
|
-
* Web Inspector (real device only)
|
|
296
|
-
* @property {boolean} [fullPageInitialization]
|
|
297
|
-
* @property {string} [pageLoadStrategy]
|
|
298
|
-
* @property {import('@appium/types').AppiumLogger} [log]
|
|
299
|
-
*/
|