appium-remote-debugger 11.4.2 → 11.5.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 +12 -0
- package/build/lib/mixins/connect.d.ts +30 -56
- package/build/lib/mixins/connect.d.ts.map +1 -1
- package/build/lib/mixins/connect.js +57 -90
- package/build/lib/mixins/connect.js.map +1 -1
- package/build/lib/mixins/cookies.d.ts +22 -0
- package/build/lib/mixins/cookies.d.ts.map +1 -0
- package/build/lib/mixins/cookies.js +48 -0
- package/build/lib/mixins/cookies.js.map +1 -0
- package/build/lib/mixins/events.d.ts +17 -2
- package/build/lib/mixins/events.d.ts.map +1 -1
- package/build/lib/mixins/events.js +29 -2
- package/build/lib/mixins/events.js.map +1 -1
- package/build/lib/mixins/execute.d.ts +5 -12
- package/build/lib/mixins/execute.d.ts.map +1 -1
- package/build/lib/mixins/execute.js +18 -30
- package/build/lib/mixins/execute.js.map +1 -1
- package/build/lib/mixins/message-handlers.d.ts +13 -23
- package/build/lib/mixins/message-handlers.d.ts.map +1 -1
- package/build/lib/mixins/message-handlers.js +56 -27
- package/build/lib/mixins/message-handlers.js.map +1 -1
- package/build/lib/mixins/misc.d.ts +51 -0
- package/build/lib/mixins/misc.d.ts.map +1 -0
- package/build/lib/mixins/misc.js +132 -0
- package/build/lib/mixins/misc.js.map +1 -0
- package/build/lib/mixins/navigate.d.ts +20 -29
- package/build/lib/mixins/navigate.d.ts.map +1 -1
- package/build/lib/mixins/navigate.js +25 -23
- package/build/lib/mixins/navigate.js.map +1 -1
- package/build/lib/mixins/screenshot.d.ts +13 -0
- package/build/lib/mixins/screenshot.d.ts.map +1 -0
- package/build/lib/mixins/screenshot.js +31 -0
- package/build/lib/mixins/screenshot.js.map +1 -0
- package/build/lib/remote-debugger-real-device.d.ts +16 -2
- package/build/lib/remote-debugger-real-device.d.ts.map +1 -1
- package/build/lib/remote-debugger-real-device.js +11 -1
- package/build/lib/remote-debugger-real-device.js.map +1 -1
- package/build/lib/remote-debugger.d.ts +153 -174
- package/build/lib/remote-debugger.d.ts.map +1 -1
- package/build/lib/remote-debugger.js +147 -213
- package/build/lib/remote-debugger.js.map +1 -1
- package/build/lib/rpc/rpc-client.d.ts +2 -1
- package/build/lib/rpc/rpc-client.d.ts.map +1 -1
- package/build/lib/rpc/rpc-client.js +2 -0
- package/build/lib/rpc/rpc-client.js.map +1 -1
- package/build/lib/utils.d.ts +20 -16
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +33 -25
- package/build/lib/utils.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/mixins/connect.js +61 -105
- package/lib/mixins/cookies.js +45 -0
- package/lib/mixins/events.js +25 -1
- package/lib/mixins/execute.js +18 -39
- package/lib/mixins/message-handlers.js +67 -36
- package/lib/mixins/misc.js +128 -0
- package/lib/mixins/navigate.js +26 -30
- package/lib/mixins/screenshot.js +34 -0
- package/lib/remote-debugger-real-device.js +14 -1
- package/lib/remote-debugger.js +133 -305
- package/lib/rpc/rpc-client.js +3 -1
- package/lib/utils.js +42 -38
- package/package.json +1 -1
- package/build/lib/mixins/index.d.ts +0 -5
- package/build/lib/mixins/index.d.ts.map +0 -1
- package/build/lib/mixins/index.js +0 -16
- package/build/lib/mixins/index.js.map +0 -1
- package/lib/mixins/index.js +0 -14
package/lib/remote-debugger.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
-
import
|
|
2
|
+
import defaultLog from './logger';
|
|
3
3
|
import { RpcClientSimulator } from './rpc';
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
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';
|
|
6
13
|
import _ from 'lodash';
|
|
7
|
-
import B from 'bluebird';
|
|
8
|
-
import path from 'path';
|
|
9
14
|
import AsyncLock from 'async-lock';
|
|
10
15
|
|
|
11
|
-
const REMOTE_DEBUGGER_PORT = 27753;
|
|
12
|
-
const SAFARI_BUNDLE_ID = 'com.apple.mobilesafari';
|
|
13
|
-
|
|
16
|
+
export const REMOTE_DEBUGGER_PORT = 27753;
|
|
14
17
|
/* How many milliseconds to wait for webkit to return a response before timing out */
|
|
15
|
-
const RPC_RESPONSE_TIMEOUT_MS = 5000;
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
+
export const RPC_RESPONSE_TIMEOUT_MS = 5000;
|
|
19
|
+
const PAGE_READY_TIMEOUT_MS = 5000;
|
|
20
|
+
const { version: MODULE_VERSION } = getModuleProperties();
|
|
18
21
|
|
|
19
|
-
const GARBAGE_COLLECT_TIMEOUT = 5000;
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
class RemoteDebugger extends EventEmitter {
|
|
23
|
+
export class RemoteDebugger extends EventEmitter {
|
|
23
24
|
// properties
|
|
24
|
-
/** @type {
|
|
25
|
+
/** @type {string[]|undefined} */
|
|
25
26
|
_skippedApps;
|
|
26
27
|
/** @type {Record<string, any>} */
|
|
27
28
|
_clientEventListeners;
|
|
@@ -37,14 +38,16 @@ class RemoteDebugger extends EventEmitter {
|
|
|
37
38
|
currentState;
|
|
38
39
|
/** @type {boolean|undefined} */
|
|
39
40
|
connected;
|
|
40
|
-
/** @type {
|
|
41
|
+
/** @type {import('bluebird')<void>} */
|
|
41
42
|
pageLoadDelay;
|
|
42
|
-
/** @type {
|
|
43
|
+
/** @type {import('bluebird')<void>} */
|
|
43
44
|
navigationDelay;
|
|
44
|
-
/** @type {import('./rpc/rpc-client').
|
|
45
|
+
/** @type {import('./rpc/rpc-client').RpcClient?} */
|
|
45
46
|
rpcClient;
|
|
46
47
|
/** @type {string|undefined} */
|
|
47
48
|
pageLoadStrategy;
|
|
49
|
+
/** @type {import('@appium/types').AppiumLogger} */
|
|
50
|
+
_log;
|
|
48
51
|
|
|
49
52
|
// events
|
|
50
53
|
/** @type {string} */
|
|
@@ -55,83 +58,46 @@ class RemoteDebugger extends EventEmitter {
|
|
|
55
58
|
static EVENT_FRAMES_DETACHED;
|
|
56
59
|
|
|
57
60
|
// methods
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
/** @type {(url: string) => Promise<void>} */
|
|
89
|
-
navToUrl;
|
|
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;
|
|
90
91
|
|
|
91
92
|
// Callbacks
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/** @type {(err: Error?, dict: Record<string, any>) => Promise<void>} */
|
|
101
|
-
onAppUpdate;
|
|
102
|
-
/** @type {(err: Error?, drivers: Record<string, any>) => void} */
|
|
103
|
-
onConnectedDriverList;
|
|
104
|
-
/** @type {(err: Error?, state: Record<string, any>) => void} */
|
|
105
|
-
onCurrentState;
|
|
106
|
-
/** @type {(err: Error?, state: Record<string, any>) => void} */
|
|
107
|
-
frameDetached;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* @typedef {Object} RemoteDebuggerOptions
|
|
111
|
-
* @property {string} [bundleId] id of the app being connected to
|
|
112
|
-
* @property {string[]} [additionalBundleIds=[]] array of possible bundle
|
|
113
|
-
* ids that the inspector could return
|
|
114
|
-
* @property {string} [platformVersion] version of iOS
|
|
115
|
-
* @property {boolean} [isSafari=true]
|
|
116
|
-
* @property {boolean} [includeSafari=false]
|
|
117
|
-
* @property {boolean} [useNewSafari=false] for web inspector, whether this is a new Safari instance
|
|
118
|
-
* @property {number} [pageLoadMs] the time, in ms, that should be waited for page loading
|
|
119
|
-
* @property {string} [host] the remote debugger's host address
|
|
120
|
-
* @property {number} [port=REMOTE_DEBUGGER_PORT] the remote debugger port through which to communicate
|
|
121
|
-
* @property {string} [socketPath]
|
|
122
|
-
* @property {number} [pageReadyTimeout=PAGE_READY_TIMEOUT]
|
|
123
|
-
* @property {string} [remoteDebugProxy]
|
|
124
|
-
* @property {boolean} [garbageCollectOnExecute=false]
|
|
125
|
-
* @property {boolean} [logFullResponse=false]
|
|
126
|
-
* @property {boolean} [logAllCommunication=false] log plists sent and received from Web Inspector
|
|
127
|
-
* @property {boolean} [logAllCommunicationHexDump=false] log communication from Web Inspector as hex dump
|
|
128
|
-
* @property {number} [webInspectorMaxFrameLength] The maximum size in bytes of a single data
|
|
129
|
-
* frame in the device communication protocol
|
|
130
|
-
* @property {number} [socketChunkSize] size, in bytes, of chunks of data sent to
|
|
131
|
-
* Web Inspector (real device only)
|
|
132
|
-
* @property {boolean} [fullPageInitialization]
|
|
133
|
-
* @property {string} [pageLoadStrategy]
|
|
134
|
-
*/
|
|
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;
|
|
135
101
|
|
|
136
102
|
/**
|
|
137
103
|
* @param {RemoteDebuggerOptions} opts
|
|
@@ -139,8 +105,9 @@ class RemoteDebugger extends EventEmitter {
|
|
|
139
105
|
constructor (opts = {}) {
|
|
140
106
|
super();
|
|
141
107
|
|
|
142
|
-
//
|
|
143
|
-
|
|
108
|
+
// @ts-ignore This is OK
|
|
109
|
+
this._log = opts.log ?? defaultLog;
|
|
110
|
+
this.log.info(`Remote Debugger version ${MODULE_VERSION}`);
|
|
144
111
|
|
|
145
112
|
const {
|
|
146
113
|
bundleId,
|
|
@@ -153,7 +120,7 @@ class RemoteDebugger extends EventEmitter {
|
|
|
153
120
|
host,
|
|
154
121
|
port = REMOTE_DEBUGGER_PORT,
|
|
155
122
|
socketPath,
|
|
156
|
-
pageReadyTimeout =
|
|
123
|
+
pageReadyTimeout = PAGE_READY_TIMEOUT_MS,
|
|
157
124
|
remoteDebugProxy,
|
|
158
125
|
garbageCollectOnExecute = false,
|
|
159
126
|
logFullResponse = false,
|
|
@@ -162,7 +129,7 @@ class RemoteDebugger extends EventEmitter {
|
|
|
162
129
|
webInspectorMaxFrameLength,
|
|
163
130
|
socketChunkSize,
|
|
164
131
|
fullPageInitialization,
|
|
165
|
-
pageLoadStrategy
|
|
132
|
+
pageLoadStrategy,
|
|
166
133
|
} = opts;
|
|
167
134
|
|
|
168
135
|
this.bundleId = bundleId;
|
|
@@ -172,7 +139,7 @@ class RemoteDebugger extends EventEmitter {
|
|
|
172
139
|
this.includeSafari = includeSafari;
|
|
173
140
|
this.useNewSafari = useNewSafari;
|
|
174
141
|
this.pageLoadMs = pageLoadMs;
|
|
175
|
-
log.debug(`useNewSafari --> ${this.useNewSafari}`);
|
|
142
|
+
this.log.debug(`useNewSafari --> ${this.useNewSafari}`);
|
|
176
143
|
|
|
177
144
|
this.garbageCollectOnExecute = garbageCollectOnExecute;
|
|
178
145
|
|
|
@@ -197,6 +164,30 @@ class RemoteDebugger extends EventEmitter {
|
|
|
197
164
|
this._lock = new AsyncLock();
|
|
198
165
|
}
|
|
199
166
|
|
|
167
|
+
/**
|
|
168
|
+
* @returns {import('@appium/types').AppiumLogger}
|
|
169
|
+
*/
|
|
170
|
+
get log() {
|
|
171
|
+
return this._log;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* @param {boolean} [checkConnected=false]
|
|
176
|
+
* @returns {import('./rpc/rpc-client').RpcClient}
|
|
177
|
+
*/
|
|
178
|
+
requireRpcClient(checkConnected = false) {
|
|
179
|
+
if (!this.rpcClient) {
|
|
180
|
+
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
181
|
+
}
|
|
182
|
+
if (checkConnected && !this.rpcClient.isConnected) {
|
|
183
|
+
throw new Error('Remote debugger is not connected');
|
|
184
|
+
}
|
|
185
|
+
return this.rpcClient;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @returns {void}
|
|
190
|
+
*/
|
|
200
191
|
setup () {
|
|
201
192
|
// app handling configuration
|
|
202
193
|
this.appDict = {};
|
|
@@ -210,8 +201,11 @@ class RemoteDebugger extends EventEmitter {
|
|
|
210
201
|
this._clientEventListeners = {};
|
|
211
202
|
}
|
|
212
203
|
|
|
204
|
+
/**
|
|
205
|
+
* @returns {void}
|
|
206
|
+
*/
|
|
213
207
|
teardown () {
|
|
214
|
-
log.debug('Cleaning up listeners');
|
|
208
|
+
this.log.debug('Cleaning up listeners');
|
|
215
209
|
|
|
216
210
|
this.appDict = {};
|
|
217
211
|
this.appIdKey = null;
|
|
@@ -224,6 +218,9 @@ class RemoteDebugger extends EventEmitter {
|
|
|
224
218
|
this.removeAllListeners(RemoteDebugger.EVENT_DISCONNECT);
|
|
225
219
|
}
|
|
226
220
|
|
|
221
|
+
/**
|
|
222
|
+
* @returns {void}
|
|
223
|
+
*/
|
|
227
224
|
initRpcClient () {
|
|
228
225
|
this.rpcClient = new RpcClientSimulator({
|
|
229
226
|
bundleId: this.bundleId,
|
|
@@ -240,234 +237,65 @@ class RemoteDebugger extends EventEmitter {
|
|
|
240
237
|
});
|
|
241
238
|
}
|
|
242
239
|
|
|
240
|
+
/**
|
|
241
|
+
* @returns {boolean}
|
|
242
|
+
*/
|
|
243
243
|
get isConnected () {
|
|
244
244
|
return !!this.rpcClient?.isConnected;
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
await this.rpcClient.send('launchApplication', {
|
|
253
|
-
bundleId: SAFARI_BUNDLE_ID
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
async startTimeline (fn) {
|
|
258
|
-
if (!this.rpcClient) {
|
|
259
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
log.debug('Starting to record the timeline');
|
|
263
|
-
this.rpcClient.on('Timeline.eventRecorded', fn);
|
|
264
|
-
return await this.rpcClient.send('Timeline.start', {
|
|
265
|
-
appIdKey: this.appIdKey,
|
|
266
|
-
pageIdKey: this.pageIdKey,
|
|
267
|
-
});
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
async stopTimeline () {
|
|
271
|
-
if (!this.rpcClient) {
|
|
272
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
log.debug('Stopping to record the timeline');
|
|
276
|
-
await this.rpcClient.send('Timeline.stop', {
|
|
277
|
-
appIdKey: this.appIdKey,
|
|
278
|
-
pageIdKey: this.pageIdKey,
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/*
|
|
283
|
-
* Keep track of the client event listeners so they can be removed
|
|
247
|
+
/**
|
|
248
|
+
* @param {boolean} allow
|
|
284
249
|
*/
|
|
285
|
-
addClientEventListener (eventName, listener) {
|
|
286
|
-
if (!this.rpcClient) {
|
|
287
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
this._clientEventListeners[eventName] = this._clientEventListeners[eventName] || [];
|
|
291
|
-
this._clientEventListeners[eventName].push(listener);
|
|
292
|
-
this.rpcClient.on(eventName, listener);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
removeClientEventListener (eventName) {
|
|
296
|
-
if (!this.rpcClient) {
|
|
297
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
for (const listener of (this._clientEventListeners[eventName] || [])) {
|
|
301
|
-
this.rpcClient.off(eventName, listener);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
startConsole (listener) {
|
|
306
|
-
log.debug('Starting to listen for JavaScript console');
|
|
307
|
-
this.addClientEventListener('Console.messageAdded', listener);
|
|
308
|
-
this.addClientEventListener('Console.messageRepeatCountUpdated', listener);
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
stopConsole () {
|
|
312
|
-
log.debug('Stopping to listen for JavaScript console');
|
|
313
|
-
this.removeClientEventListener('Console.messageAdded');
|
|
314
|
-
this.removeClientEventListener('Console.messageRepeatCountUpdated');
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
startNetwork (listener) {
|
|
318
|
-
log.debug('Starting to listen for network events');
|
|
319
|
-
this.addClientEventListener('NetworkEvent', listener);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
stopNetwork () {
|
|
323
|
-
log.debug('Stopping to listen for network events');
|
|
324
|
-
this.removeClientEventListener('NetworkEvent');
|
|
325
|
-
}
|
|
326
|
-
|
|
327
250
|
set allowNavigationWithoutReload (allow) {
|
|
328
251
|
this._allowNavigationWithoutReload = allow;
|
|
329
252
|
}
|
|
330
253
|
|
|
254
|
+
/**
|
|
255
|
+
* @returns {boolean}
|
|
256
|
+
*/
|
|
331
257
|
get allowNavigationWithoutReload () {
|
|
332
|
-
return this._allowNavigationWithoutReload;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Potentially this does not work for mobile safari
|
|
336
|
-
async overrideUserAgent (value) {
|
|
337
|
-
log.debug('Setting overrideUserAgent');
|
|
338
|
-
if (!this.rpcClient) {
|
|
339
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
return await this.rpcClient.send('Page.overrideUserAgent', {
|
|
343
|
-
appIdKey: this.appIdKey,
|
|
344
|
-
pageIdKey: this.pageIdKey,
|
|
345
|
-
value
|
|
346
|
-
});
|
|
258
|
+
return !!this._allowNavigationWithoutReload;
|
|
347
259
|
}
|
|
348
260
|
|
|
349
261
|
/**
|
|
350
|
-
*
|
|
351
|
-
* @param {ScreenshotCaptureOptions} [opts={}] if rect is null capture the whole
|
|
352
|
-
* coordinate system else capture the rect in the given coordinateSystem
|
|
353
|
-
* @returns {Promise<string>} a base64 encoded string of the screenshot
|
|
262
|
+
* @returns {string[]}
|
|
354
263
|
*/
|
|
355
|
-
async captureScreenshot(opts = {}) {
|
|
356
|
-
const {rect = null, coordinateSystem = 'Viewport'} = opts;
|
|
357
|
-
log.debug('Capturing screenshot');
|
|
358
|
-
if (!this.rpcClient) {
|
|
359
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
const arect = rect ?? /** @type {import('@appium/types').Rect} */ (await this.executeAtom(
|
|
363
|
-
'execute_script',
|
|
364
|
-
['return {x: 0, y: 0, width: window.innerWidth, height: window.innerHeight}', []]
|
|
365
|
-
));
|
|
366
|
-
const response = await this.rpcClient.send('Page.snapshotRect', {
|
|
367
|
-
...arect,
|
|
368
|
-
appIdKey: this.appIdKey,
|
|
369
|
-
pageIdKey: this.pageIdKey,
|
|
370
|
-
coordinateSystem,
|
|
371
|
-
});
|
|
372
|
-
|
|
373
|
-
if (response.error) {
|
|
374
|
-
throw new Error(response.error);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
return response.dataURL.replace(/^data:image\/png;base64,/, '');
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
async getCookies () {
|
|
381
|
-
log.debug('Getting cookies');
|
|
382
|
-
if (!this.rpcClient) {
|
|
383
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
return await this.rpcClient.send('Page.getCookies', {
|
|
387
|
-
appIdKey: this.appIdKey,
|
|
388
|
-
pageIdKey: this.pageIdKey
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
async setCookie (cookie) {
|
|
393
|
-
log.debug('Setting cookie');
|
|
394
|
-
if (!this.rpcClient) {
|
|
395
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return await this.rpcClient.send('Page.setCookie', {
|
|
399
|
-
appIdKey: this.appIdKey,
|
|
400
|
-
pageIdKey: this.pageIdKey,
|
|
401
|
-
cookie
|
|
402
|
-
});
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
async deleteCookie (cookieName, url) {
|
|
406
|
-
log.debug(`Deleting cookie '${cookieName}' on '${url}'`);
|
|
407
|
-
if (!this.rpcClient) {
|
|
408
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
return await this.rpcClient.send('Page.deleteCookie', {
|
|
412
|
-
appIdKey: this.appIdKey,
|
|
413
|
-
pageIdKey: this.pageIdKey,
|
|
414
|
-
cookieName,
|
|
415
|
-
url,
|
|
416
|
-
});
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
async garbageCollect (timeoutMs = GARBAGE_COLLECT_TIMEOUT) {
|
|
420
|
-
log.debug(`Garbage collecting with ${timeoutMs}ms timeout`);
|
|
421
|
-
if (!this.rpcClient) {
|
|
422
|
-
throw new Error(`rpcClient is undefined. Has 'initRpcClient' been called before?`);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
try {
|
|
426
|
-
checkParams({appIdKey: this.appIdKey, pageIdKey: this.pageIdKey});
|
|
427
|
-
} catch (err) {
|
|
428
|
-
log.debug(`Unable to collect garbage at this time`);
|
|
429
|
-
return;
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
await B.resolve(this.rpcClient.send('Heap.gc', {
|
|
433
|
-
appIdKey: this.appIdKey,
|
|
434
|
-
pageIdKey: this.pageIdKey,
|
|
435
|
-
})).timeout(timeoutMs)
|
|
436
|
-
.then(function gcSuccess () { // eslint-disable-line promise/prefer-await-to-then
|
|
437
|
-
log.debug(`Garbage collection successful`);
|
|
438
|
-
}).catch(function gcError (err) { // eslint-disable-line promise/prefer-await-to-callbacks
|
|
439
|
-
if (err instanceof B.TimeoutError) {
|
|
440
|
-
log.debug(`Garbage collection timed out after ${timeoutMs}ms`);
|
|
441
|
-
} else {
|
|
442
|
-
log.debug(`Unable to collect garbage: ${err.message}`);
|
|
443
|
-
}
|
|
444
|
-
});
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
async useAppDictLock (fn) {
|
|
448
|
-
return await this._lock.acquire('appDict', fn);
|
|
449
|
-
}
|
|
450
|
-
|
|
451
264
|
get skippedApps () {
|
|
452
|
-
return this._skippedApps
|
|
265
|
+
return this._skippedApps ?? [];
|
|
453
266
|
}
|
|
454
267
|
}
|
|
455
268
|
|
|
456
|
-
for (const [name,
|
|
457
|
-
RemoteDebugger.prototype[name] = fn;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
for (const [name, event] of _.toPairs(events)) {
|
|
269
|
+
for (const [name, event] of _.toPairs(eventMixins.events)) {
|
|
461
270
|
RemoteDebugger[name] = event;
|
|
462
271
|
}
|
|
463
272
|
|
|
464
273
|
export default RemoteDebugger;
|
|
465
|
-
export {
|
|
466
|
-
RemoteDebugger, REMOTE_DEBUGGER_PORT, RPC_RESPONSE_TIMEOUT_MS,
|
|
467
|
-
};
|
|
468
274
|
|
|
469
275
|
/**
|
|
470
|
-
* @typedef {Object}
|
|
471
|
-
* @property {
|
|
472
|
-
* @property {
|
|
276
|
+
* @typedef {Object} RemoteDebuggerOptions
|
|
277
|
+
* @property {string} [bundleId] id of the app being connected to
|
|
278
|
+
* @property {string[]} [additionalBundleIds=[]] array of possible bundle
|
|
279
|
+
* ids that the inspector could return
|
|
280
|
+
* @property {string} [platformVersion] version of iOS
|
|
281
|
+
* @property {boolean} [isSafari=true]
|
|
282
|
+
* @property {boolean} [includeSafari=false]
|
|
283
|
+
* @property {boolean} [useNewSafari=false] for web inspector, whether this is a new Safari instance
|
|
284
|
+
* @property {number} [pageLoadMs] the time, in ms, that should be waited for page loading
|
|
285
|
+
* @property {string} [host] the remote debugger's host address
|
|
286
|
+
* @property {number} [port=REMOTE_DEBUGGER_PORT] the remote debugger port through which to communicate
|
|
287
|
+
* @property {string} [socketPath]
|
|
288
|
+
* @property {number} [pageReadyTimeout=PAGE_READY_TIMEOUT]
|
|
289
|
+
* @property {string} [remoteDebugProxy]
|
|
290
|
+
* @property {boolean} [garbageCollectOnExecute=false]
|
|
291
|
+
* @property {boolean} [logFullResponse=false]
|
|
292
|
+
* @property {boolean} [logAllCommunication=false] log plists sent and received from Web Inspector
|
|
293
|
+
* @property {boolean} [logAllCommunicationHexDump=false] log communication from Web Inspector as hex dump
|
|
294
|
+
* @property {number} [webInspectorMaxFrameLength] The maximum size in bytes of a single data
|
|
295
|
+
* frame in the device communication protocol
|
|
296
|
+
* @property {number} [socketChunkSize] size, in bytes, of chunks of data sent to
|
|
297
|
+
* Web Inspector (real device only)
|
|
298
|
+
* @property {boolean} [fullPageInitialization]
|
|
299
|
+
* @property {string} [pageLoadStrategy]
|
|
300
|
+
* @property {import('@appium/types').AppiumLogger} [log]
|
|
473
301
|
*/
|
package/lib/rpc/rpc-client.js
CHANGED
|
@@ -29,7 +29,7 @@ function isTargetBased (isSafari, platformVersion) {
|
|
|
29
29
|
return isHighVersion;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export
|
|
32
|
+
export class RpcClient {
|
|
33
33
|
/** @type {RpcMessageHandler|undefined} */
|
|
34
34
|
messageHandler;
|
|
35
35
|
|
|
@@ -696,3 +696,5 @@ export default class RpcClient {
|
|
|
696
696
|
log.debug(`Script parsed: ${JSON.stringify(scriptInfo)}`);
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
|
+
|
|
700
|
+
export default RpcClient;
|