appium-remote-debugger 12.2.9 → 13.0.0
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 +16 -0
- package/build/lib/mixins/connect.d.ts.map +1 -1
- package/build/lib/mixins/connect.js +32 -37
- package/build/lib/mixins/connect.js.map +1 -1
- package/build/lib/mixins/execute.d.ts.map +1 -1
- package/build/lib/mixins/execute.js +14 -12
- package/build/lib/mixins/execute.js.map +1 -1
- package/build/lib/mixins/navigate.d.ts.map +1 -1
- package/build/lib/mixins/navigate.js +9 -96
- package/build/lib/mixins/navigate.js.map +1 -1
- package/build/lib/protocol/index.d.ts +3 -1
- package/build/lib/protocol/index.d.ts.map +1 -1
- package/build/lib/protocol/index.js +22 -23
- package/build/lib/protocol/index.js.map +1 -1
- package/build/lib/rpc/index.d.ts +1 -2
- package/build/lib/rpc/index.d.ts.map +1 -1
- package/build/lib/rpc/index.js +1 -36
- package/build/lib/rpc/index.js.map +1 -1
- package/build/lib/rpc/remote-messages.d.ts +24 -18
- package/build/lib/rpc/remote-messages.d.ts.map +1 -1
- package/build/lib/rpc/remote-messages.js +24 -11
- 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 +1 -3
- 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 +1 -3
- package/build/lib/rpc/rpc-client-simulator.js.map +1 -1
- package/build/lib/rpc/rpc-client.d.ts +63 -44
- package/build/lib/rpc/rpc-client.d.ts.map +1 -1
- package/build/lib/rpc/rpc-client.js +209 -122
- package/build/lib/rpc/rpc-client.js.map +1 -1
- package/build/lib/rpc/rpc-message-handler.d.ts +14 -6
- package/build/lib/rpc/rpc-message-handler.d.ts.map +1 -1
- package/build/lib/rpc/rpc-message-handler.js +70 -68
- package/build/lib/rpc/rpc-message-handler.js.map +1 -1
- package/build/lib/types.d.ts +28 -3
- package/build/lib/types.d.ts.map +1 -1
- package/build/lib/utils.d.ts +4 -3
- package/build/lib/utils.d.ts.map +1 -1
- package/build/lib/utils.js +4 -2
- package/build/lib/utils.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/lib/mixins/connect.js +34 -38
- package/lib/mixins/execute.js +15 -12
- package/lib/mixins/navigate.js +11 -99
- package/lib/protocol/index.js +22 -24
- package/lib/rpc/index.js +1 -3
- package/lib/rpc/remote-messages.js +28 -11
- package/lib/rpc/rpc-client-real-device.js +1 -3
- package/lib/rpc/rpc-client-simulator.js +1 -3
- package/lib/rpc/rpc-client.js +244 -133
- package/lib/rpc/rpc-message-handler.js +71 -67
- package/lib/types.ts +33 -3
- package/lib/utils.js +4 -2
- package/package.json +2 -1
- package/build/lib/rpc/constants.d.ts +0 -2
- package/build/lib/rpc/constants.d.ts.map +0 -1
- package/build/lib/rpc/constants.js +0 -5
- package/build/lib/rpc/constants.js.map +0 -1
- package/lib/rpc/constants.js +0 -1
package/lib/mixins/connect.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
getBundleId,
|
|
19
19
|
getAdditionalBundleIds,
|
|
20
20
|
} from './property-accessors';
|
|
21
|
+
import { NEW_APP_CONNECTED_ERROR, EMPTY_PAGE_DICTIONARY_ERROR } from '../rpc/rpc-client';
|
|
21
22
|
|
|
22
23
|
const APP_CONNECT_TIMEOUT_MS = 0;
|
|
23
24
|
const APP_CONNECT_INTERVAL_MS = 100;
|
|
@@ -118,48 +119,41 @@ export async function disconnect () {
|
|
|
118
119
|
*/
|
|
119
120
|
export async function selectApp (currentUrl = null, maxTries = SELECT_APP_RETRIES, ignoreAboutBlankUrl = false) {
|
|
120
121
|
this.log.debug('Selecting application');
|
|
121
|
-
const rpcClient = this.requireRpcClient();
|
|
122
122
|
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.log.debug('No applications currently connected.');
|
|
129
|
-
return [];
|
|
130
|
-
}
|
|
123
|
+
const timer = new timing.Timer().start();
|
|
124
|
+
if (_.isEmpty(getAppDict(this))) {
|
|
125
|
+
this.log.debug('No applications currently connected.');
|
|
126
|
+
return [];
|
|
127
|
+
}
|
|
131
128
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
const { appIdKey } = await searchForApp.bind(this)(currentUrl, maxTries, ignoreAboutBlankUrl);
|
|
130
|
+
if (getAppIdKey(this) !== appIdKey) {
|
|
131
|
+
this.log.debug(`Received altered app id, updating from '${getAppIdKey(this)}' to '${appIdKey}'`);
|
|
132
|
+
setAppIdKey(this, appIdKey);
|
|
133
|
+
}
|
|
134
|
+
logApplicationDictionary.bind(this)();
|
|
135
|
+
// translate the dictionary into a useful form, and return to sender
|
|
136
|
+
this.log.debug(`Finally selecting app ${getAppIdKey(this)}`);
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
138
|
+
/** @type {import('../types').Page[]} */
|
|
139
|
+
const fullPageArray = [];
|
|
140
|
+
for (const [app, info] of _.toPairs(getAppDict(this))) {
|
|
141
|
+
if (!_.isArray(info.pageArray) || !info.isActive) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
const id = app.replace('PID:', '');
|
|
145
|
+
for (const page of info.pageArray) {
|
|
146
|
+
if (!(ignoreAboutBlankUrl && page.url === BLANK_PAGE_URL)) {
|
|
147
|
+
const pageDict = _.clone(page);
|
|
148
|
+
pageDict.id = `${id}.${pageDict.id}`;
|
|
149
|
+
pageDict.bundleId = info.bundleId;
|
|
150
|
+
fullPageArray.push(pageDict);
|
|
155
151
|
}
|
|
156
152
|
}
|
|
157
|
-
|
|
158
|
-
this.log.debug(`Selected app after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
159
|
-
return fullPageArray;
|
|
160
|
-
} finally {
|
|
161
|
-
rpcClient.shouldCheckForTarget = shouldCheckForTarget;
|
|
162
153
|
}
|
|
154
|
+
|
|
155
|
+
this.log.debug(`Selected app after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
|
|
156
|
+
return fullPageArray;
|
|
163
157
|
}
|
|
164
158
|
|
|
165
159
|
/**
|
|
@@ -243,8 +237,10 @@ async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) {
|
|
|
243
237
|
this.log.debug('Received app, but no match was found. Trying again.');
|
|
244
238
|
}
|
|
245
239
|
} catch (err) {
|
|
246
|
-
|
|
247
|
-
|
|
240
|
+
if (![NEW_APP_CONNECTED_ERROR, EMPTY_PAGE_DICTIONARY_ERROR].some((msg) => msg === err.message)) {
|
|
241
|
+
this.log.debug(err.stack);
|
|
242
|
+
}
|
|
243
|
+
this.log.warn(`The application ${attemptedAppIdKey} is not connectable yet: ${err.message}`);
|
|
248
244
|
}
|
|
249
245
|
}
|
|
250
246
|
retryCount++;
|
package/lib/mixins/execute.js
CHANGED
|
@@ -140,23 +140,26 @@ export async function execute (command, override) {
|
|
|
140
140
|
await this.waitForDom();
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
throw new Error('Missing parameter: pageIdKey. Is the target web page still alive?');
|
|
148
|
-
}
|
|
143
|
+
const {appIdKey, pageIdKey} = checkParams({
|
|
144
|
+
appIdKey: getAppIdKey(this),
|
|
145
|
+
pageIdKey: getPageIdKey(this),
|
|
146
|
+
});
|
|
149
147
|
|
|
150
148
|
if (getGarbageCollectOnExecute(this)) {
|
|
151
149
|
await this.garbageCollect();
|
|
152
150
|
}
|
|
153
151
|
|
|
152
|
+
const rpcClient = this.requireRpcClient(true);
|
|
153
|
+
await rpcClient.waitForPageInitialization(
|
|
154
|
+
/** @type {import('../types').AppIdKey} */ (appIdKey),
|
|
155
|
+
/** @type {import('../types').PageIdKey} */ (pageIdKey)
|
|
156
|
+
);
|
|
154
157
|
this.log.debug(`Sending javascript command: '${_.truncate(command, {length: 50})}'`);
|
|
155
|
-
const res = await
|
|
158
|
+
const res = await rpcClient.send('Runtime.evaluate', {
|
|
156
159
|
expression: command,
|
|
157
160
|
returnByValue: true,
|
|
158
|
-
appIdKey
|
|
159
|
-
pageIdKey
|
|
161
|
+
appIdKey,
|
|
162
|
+
pageIdKey,
|
|
160
163
|
});
|
|
161
164
|
return convertResult(res);
|
|
162
165
|
}
|
|
@@ -168,7 +171,7 @@ export async function execute (command, override) {
|
|
|
168
171
|
* @param {any[]} [args]
|
|
169
172
|
*/
|
|
170
173
|
export async function callFunction (objectId, fn, args) {
|
|
171
|
-
checkParams({
|
|
174
|
+
const {appIdKey, pageIdKey} = checkParams({
|
|
172
175
|
appIdKey: getAppIdKey(this),
|
|
173
176
|
pageIdKey: getPageIdKey(this),
|
|
174
177
|
});
|
|
@@ -183,8 +186,8 @@ export async function callFunction (objectId, fn, args) {
|
|
|
183
186
|
functionDeclaration: fn,
|
|
184
187
|
arguments: args,
|
|
185
188
|
returnByValue: true,
|
|
186
|
-
appIdKey
|
|
187
|
-
pageIdKey
|
|
189
|
+
appIdKey,
|
|
190
|
+
pageIdKey,
|
|
188
191
|
});
|
|
189
192
|
|
|
190
193
|
return convertResult(res);
|
package/lib/mixins/navigate.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { checkParams
|
|
1
|
+
import { checkParams } from '../utils';
|
|
2
2
|
import { events } from './events';
|
|
3
3
|
import { timing, util } from '@appium/support';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import B, { TimeoutError as BTimeoutError } from 'bluebird';
|
|
6
|
-
import { errors } from '@appium/base-driver';
|
|
7
|
-
import { rpcConstants } from '../rpc';
|
|
8
6
|
import {
|
|
9
7
|
getAppIdKey,
|
|
10
8
|
setPageLoading,
|
|
@@ -18,8 +16,6 @@ import {
|
|
|
18
16
|
|
|
19
17
|
export const DEFAULT_PAGE_READINESS_TIMEOUT_MS = 20 * 1000;
|
|
20
18
|
const PAGE_READINESS_CHECK_INTERVAL_MS = 50;
|
|
21
|
-
const PAGE_READINESS_JS_MIN_CHECK_INTERVAL_MS = 1000;
|
|
22
|
-
const CONSOLE_ENABLEMENT_TIMEOUT_MS = 20 * 1000;
|
|
23
19
|
|
|
24
20
|
/**
|
|
25
21
|
* pageLoadStrategy in WebDriver definitions.
|
|
@@ -146,10 +142,6 @@ export async function waitForDom (startPageLoadTimer) {
|
|
|
146
142
|
* @returns {Promise<boolean>}
|
|
147
143
|
*/
|
|
148
144
|
export async function checkPageIsReady (timeoutMs) {
|
|
149
|
-
checkParams({
|
|
150
|
-
appIdKey: getAppIdKey(this),
|
|
151
|
-
});
|
|
152
|
-
|
|
153
145
|
const readyCmd = 'document.readyState;';
|
|
154
146
|
const actualTimeoutMs = timeoutMs ?? getPageReadyTimeout(this);
|
|
155
147
|
try {
|
|
@@ -173,9 +165,10 @@ export async function checkPageIsReady (timeoutMs) {
|
|
|
173
165
|
* @returns {Promise<void>}
|
|
174
166
|
*/
|
|
175
167
|
export async function navToUrl (url) {
|
|
176
|
-
const appIdKey =
|
|
177
|
-
|
|
178
|
-
|
|
168
|
+
const {appIdKey, pageIdKey} = checkParams({
|
|
169
|
+
appIdKey: getAppIdKey(this),
|
|
170
|
+
pageIdKey: getPageIdKey(this),
|
|
171
|
+
});
|
|
179
172
|
const rpcClient = this.requireRpcClient();
|
|
180
173
|
|
|
181
174
|
try {
|
|
@@ -184,43 +177,25 @@ export async function navToUrl (url) {
|
|
|
184
177
|
throw new TypeError(`'${url}' is not a valid URL`);
|
|
185
178
|
}
|
|
186
179
|
|
|
187
|
-
setNavigatingToPage(this, true);
|
|
188
180
|
this.log.debug(`Navigating to new URL: '${url}'`);
|
|
181
|
+
setNavigatingToPage(this, true);
|
|
182
|
+
await rpcClient.waitForPageInitialization(
|
|
183
|
+
/** @type {import('../types').AppIdKey} */ (appIdKey),
|
|
184
|
+
/** @type {import('../types').PageIdKey} */ (pageIdKey)
|
|
185
|
+
);
|
|
189
186
|
const readinessTimeoutMs = this.pageLoadMs;
|
|
190
187
|
/** @type {(() => void)|undefined} */
|
|
191
188
|
let onPageLoaded;
|
|
192
|
-
/** @type {(() => void)|undefined} */
|
|
193
|
-
let onPageChanged;
|
|
194
|
-
/** @type {(() => void)|undefined} */
|
|
195
|
-
let onTargetProvisioned;
|
|
196
189
|
/** @type {NodeJS.Timeout|undefined|null} */
|
|
197
190
|
let onPageLoadedTimeout;
|
|
198
191
|
setPageLoadDelay(this, util.cancellableDelay(readinessTimeoutMs));
|
|
199
192
|
setPageLoading(this, true);
|
|
200
193
|
let isPageLoading = true;
|
|
201
|
-
|
|
202
|
-
/** @type {Promise<void>|null} */
|
|
203
|
-
let pageReadinessCheckPromise = null;
|
|
194
|
+
// /** @type {Promise<void>|null} */
|
|
204
195
|
const start = new timing.Timer().start();
|
|
205
196
|
|
|
206
197
|
/** @type {B<void>} */
|
|
207
198
|
const pageReadinessPromise = new B((resolve) => {
|
|
208
|
-
const performPageReadinessCheck = async () => {
|
|
209
|
-
while (isPageLoading) {
|
|
210
|
-
const pageReadyCheckStart = new timing.Timer().start();
|
|
211
|
-
try {
|
|
212
|
-
const isReady = await this.checkPageIsReady(PAGE_READINESS_JS_MIN_CHECK_INTERVAL_MS);
|
|
213
|
-
if (isReady && isPageLoading && onPageLoaded) {
|
|
214
|
-
return onPageLoaded();
|
|
215
|
-
}
|
|
216
|
-
} catch {}
|
|
217
|
-
const msLeft = PAGE_READINESS_JS_MIN_CHECK_INTERVAL_MS - pageReadyCheckStart.getDuration().asMilliSeconds;
|
|
218
|
-
if (msLeft > 0 && isPageLoading) {
|
|
219
|
-
await B.delay(msLeft);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
};
|
|
223
|
-
|
|
224
199
|
onPageLoadedTimeout = setTimeout(() => {
|
|
225
200
|
if (isPageLoading) {
|
|
226
201
|
isPageLoading = false;
|
|
@@ -241,53 +216,11 @@ export async function navToUrl (url) {
|
|
|
241
216
|
clearTimeout(onPageLoadedTimeout);
|
|
242
217
|
onPageLoadedTimeout = null;
|
|
243
218
|
}
|
|
244
|
-
didPageFinishLoad = true;
|
|
245
219
|
return resolve();
|
|
246
220
|
};
|
|
247
221
|
|
|
248
|
-
// Sometimes it could be observed that we do not receive
|
|
249
|
-
// any events for target provisioning while navigating to a new page,
|
|
250
|
-
// but only events related to the page change.
|
|
251
|
-
// So lets just start the monitoring loop as soon as any of these events arrives
|
|
252
|
-
// for the target page.
|
|
253
|
-
onPageChanged = async (
|
|
254
|
-
/** @type {Error|null} */ err,
|
|
255
|
-
/** @type {string} */ _appIdKey,
|
|
256
|
-
/** @type {import("@appium/types").StringRecord} */ pageDict
|
|
257
|
-
) => {
|
|
258
|
-
if (_appIdKey !== appIdKey) {
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/** @type {import('../types').Page|undefined} */
|
|
263
|
-
const targetPage = pageArrayFromDict(pageDict)
|
|
264
|
-
.find(({id}) => parseInt(`${id}`, 10) === parseInt(`${pageIdKey}`, 10));
|
|
265
|
-
if (targetPage?.url === url) {
|
|
266
|
-
this.log.debug(`The page ${targetPage.id} has the expected URL ${url}`);
|
|
267
|
-
if (pageReadinessCheckPromise) {
|
|
268
|
-
this.log.debug('Page readiness monitoring is already running');
|
|
269
|
-
} else {
|
|
270
|
-
this.log.debug('Monitoring page readiness');
|
|
271
|
-
pageReadinessCheckPromise = performPageReadinessCheck();
|
|
272
|
-
await pageReadinessCheckPromise;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
rpcClient.on('_rpc_forwardGetListing:', onPageChanged);
|
|
277
|
-
|
|
278
222
|
// https://chromedevtools.github.io/devtools-protocol/tot/Page/#event-loadEventFired
|
|
279
223
|
rpcClient.once('Page.loadEventFired', onPageLoaded);
|
|
280
|
-
onTargetProvisioned = async () => {
|
|
281
|
-
this.log.debug('The page target has been provisioned');
|
|
282
|
-
if (pageReadinessCheckPromise) {
|
|
283
|
-
this.log.debug('Page readiness monitoring is already running');
|
|
284
|
-
} else {
|
|
285
|
-
this.log.debug('Monitoring page readiness');
|
|
286
|
-
pageReadinessCheckPromise = performPageReadinessCheck();
|
|
287
|
-
await pageReadinessCheckPromise;
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
rpcClient.targetSubscriptions.once(rpcConstants.ON_TARGET_PROVISIONED_EVENT, onTargetProvisioned);
|
|
291
224
|
|
|
292
225
|
rpcClient.send('Page.navigate', {
|
|
293
226
|
url,
|
|
@@ -313,30 +246,9 @@ export async function navToUrl (url) {
|
|
|
313
246
|
clearTimeout(onPageLoadedTimeout);
|
|
314
247
|
onPageLoadedTimeout = null;
|
|
315
248
|
}
|
|
316
|
-
if (onTargetProvisioned) {
|
|
317
|
-
rpcClient.targetSubscriptions.off(rpcConstants.ON_TARGET_PROVISIONED_EVENT, onTargetProvisioned);
|
|
318
|
-
}
|
|
319
249
|
if (onPageLoaded) {
|
|
320
250
|
rpcClient.off('Page.loadEventFired', onPageLoaded);
|
|
321
251
|
}
|
|
322
|
-
if (onPageChanged) {
|
|
323
|
-
rpcClient.off('_rpc_forwardGetListing:', onPageChanged);
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
// enable console logging, so we get the events (otherwise we only
|
|
328
|
-
// get notified when navigating to a local page
|
|
329
|
-
try {
|
|
330
|
-
await B.resolve(rpcClient.send('Console.enable', {
|
|
331
|
-
appIdKey: getAppIdKey(this),
|
|
332
|
-
pageIdKey: getPageIdKey(this),
|
|
333
|
-
}, didPageFinishLoad)).timeout(CONSOLE_ENABLEMENT_TIMEOUT_MS);
|
|
334
|
-
} catch (err) {
|
|
335
|
-
if (err instanceof BTimeoutError) {
|
|
336
|
-
throw new errors.TimeoutError(`Could not enable console events after the page load within ` +
|
|
337
|
-
`${CONSOLE_ENABLEMENT_TIMEOUT_MS}ms. The Web Inspector/Safari may need to be restarted.`);
|
|
338
|
-
}
|
|
339
|
-
throw err;
|
|
340
252
|
}
|
|
341
253
|
}
|
|
342
254
|
|
package/lib/protocol/index.js
CHANGED
|
@@ -175,6 +175,8 @@ const COMMANDS = /** @type {const} */ ({
|
|
|
175
175
|
// https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/inspector/protocol/Target.json
|
|
176
176
|
//#region TARGET DOMAIN
|
|
177
177
|
'Target.exists': [], // removed since WebKit in 13.4
|
|
178
|
+
'Target.setPauseOnStart': ['pauseOnStart'],
|
|
179
|
+
'Target.resume': ['targetId'],
|
|
178
180
|
//#endregion
|
|
179
181
|
|
|
180
182
|
// https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/inspector/protocol/Timeline.json
|
|
@@ -196,36 +198,16 @@ const COMMANDS = /** @type {const} */ ({
|
|
|
196
198
|
//#endregion
|
|
197
199
|
});
|
|
198
200
|
|
|
199
|
-
/**
|
|
200
|
-
*
|
|
201
|
-
* @param {string} id
|
|
202
|
-
* @param {string} method
|
|
203
|
-
* @param {import('@appium/types').StringRecord} params
|
|
204
|
-
* @returns {import('../types').ProtocolCommandOpts}
|
|
205
|
-
*/
|
|
206
|
-
function getCommand (id, method, params = {}) {
|
|
207
|
-
return {
|
|
208
|
-
id,
|
|
209
|
-
method,
|
|
210
|
-
params: Object.assign({
|
|
211
|
-
objectGroup: OBJECT_GROUP,
|
|
212
|
-
includeCommandLineAPI: true,
|
|
213
|
-
doNotPauseOnExceptionsAndMuteConsole: false,
|
|
214
|
-
emulateUserGesture: false,
|
|
215
|
-
generatePreview: false,
|
|
216
|
-
saveResult: false,
|
|
217
|
-
}, params),
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
201
|
/**
|
|
222
202
|
*
|
|
223
203
|
* @param {string} id
|
|
224
204
|
* @param {string} method
|
|
225
205
|
* @param {import('../types').RemoteCommandOpts} opts
|
|
206
|
+
* @param {boolean} [direct=false] - if set to false then the resulting command params
|
|
207
|
+
* will be patched with default values
|
|
226
208
|
* @returns {import('../types').ProtocolCommandOpts}
|
|
227
209
|
*/
|
|
228
|
-
export function getProtocolCommand (id, method, opts) {
|
|
210
|
+
export function getProtocolCommand (id, method, opts, direct = false) {
|
|
229
211
|
const paramNames = COMMANDS[method];
|
|
230
212
|
if (!paramNames) {
|
|
231
213
|
throw new Error(`Unknown command: '${method}'`);
|
|
@@ -235,7 +217,23 @@ export function getProtocolCommand (id, method, opts) {
|
|
|
235
217
|
params[name] = opts[name];
|
|
236
218
|
return params;
|
|
237
219
|
}, {});
|
|
238
|
-
|
|
220
|
+
const result = {
|
|
221
|
+
id,
|
|
222
|
+
method,
|
|
223
|
+
params,
|
|
224
|
+
};
|
|
225
|
+
if (!direct) {
|
|
226
|
+
result.params = {
|
|
227
|
+
objectGroup: OBJECT_GROUP,
|
|
228
|
+
includeCommandLineAPI: true,
|
|
229
|
+
doNotPauseOnExceptionsAndMuteConsole: false,
|
|
230
|
+
emulateUserGesture: false,
|
|
231
|
+
generatePreview: false,
|
|
232
|
+
saveResult: false,
|
|
233
|
+
...result.params,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
239
237
|
}
|
|
240
238
|
|
|
241
239
|
export default getProtocolCommand;
|
package/lib/rpc/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { RpcClientSimulator } from './rpc-client-simulator';
|
|
2
2
|
import { RpcClientRealDevice } from './rpc-client-real-device';
|
|
3
|
-
import * as rpcConstants from './constants';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
export { RpcClientSimulator, RpcClientRealDevice, rpcConstants };
|
|
4
|
+
export { RpcClientSimulator, RpcClientRealDevice };
|
|
@@ -19,6 +19,8 @@ const COMMANDS = /** @type {const} */ ({
|
|
|
19
19
|
'Runtime.evaluate': FULL_COMMAND,
|
|
20
20
|
|
|
21
21
|
'Target.exists': DIRECT_COMMAND,
|
|
22
|
+
'Target.setPauseOnStart': DIRECT_COMMAND,
|
|
23
|
+
'Target.resume': DIRECT_COMMAND,
|
|
22
24
|
|
|
23
25
|
'Timeline.start': FULL_COMMAND,
|
|
24
26
|
'Timeline.stop': FULL_COMMAND,
|
|
@@ -49,7 +51,7 @@ export class RemoteMessages {
|
|
|
49
51
|
/**
|
|
50
52
|
*
|
|
51
53
|
* @param {string} connId
|
|
52
|
-
* @returns {import('../types').
|
|
54
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
53
55
|
*/
|
|
54
56
|
setConnectionKey (connId) {
|
|
55
57
|
return {
|
|
@@ -64,7 +66,7 @@ export class RemoteMessages {
|
|
|
64
66
|
*
|
|
65
67
|
* @param {string} connId
|
|
66
68
|
* @param {import('../types').AppIdKey} appIdKey
|
|
67
|
-
* @returns {import('../types').
|
|
69
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
68
70
|
*/
|
|
69
71
|
connectToApp (connId, appIdKey) {
|
|
70
72
|
return {
|
|
@@ -82,7 +84,7 @@ export class RemoteMessages {
|
|
|
82
84
|
* @param {string} senderId
|
|
83
85
|
* @param {import('../types').AppIdKey} appIdKey
|
|
84
86
|
* @param {import('../types').PageIdKey} [pageIdKey]
|
|
85
|
-
* @returns {import('../types').
|
|
87
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
86
88
|
*/
|
|
87
89
|
setSenderKey (connId, senderId, appIdKey, pageIdKey) {
|
|
88
90
|
return {
|
|
@@ -91,7 +93,7 @@ export class RemoteMessages {
|
|
|
91
93
|
WIRConnectionIdentifierKey: connId,
|
|
92
94
|
WIRSenderKey: senderId,
|
|
93
95
|
WIRPageIdentifierKey: pageIdKey,
|
|
94
|
-
WIRAutomaticallyPause: false
|
|
96
|
+
WIRAutomaticallyPause: false,
|
|
95
97
|
},
|
|
96
98
|
__selector: '_rpc_forwardSocketSetup:'
|
|
97
99
|
};
|
|
@@ -103,7 +105,7 @@ export class RemoteMessages {
|
|
|
103
105
|
* @param {import('../types').AppIdKey} appIdKey
|
|
104
106
|
* @param {import('../types').PageIdKey} [pageIdKey]
|
|
105
107
|
* @param {boolean} [enabled]
|
|
106
|
-
* @returns {import('../types').
|
|
108
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
107
109
|
*/
|
|
108
110
|
indicateWebView (connId, appIdKey, pageIdKey, enabled) {
|
|
109
111
|
return {
|
|
@@ -120,7 +122,7 @@ export class RemoteMessages {
|
|
|
120
122
|
/**
|
|
121
123
|
*
|
|
122
124
|
* @param {string} bundleId
|
|
123
|
-
* @returns {import('../types').
|
|
125
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
124
126
|
*/
|
|
125
127
|
launchApplication (bundleId) {
|
|
126
128
|
return {
|
|
@@ -134,7 +136,7 @@ export class RemoteMessages {
|
|
|
134
136
|
/**
|
|
135
137
|
*
|
|
136
138
|
* @param {import('../types').RemoteCommandOpts & import('../types').ProtocolCommandOpts} opts
|
|
137
|
-
* @returns {import('../types').
|
|
139
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
138
140
|
*/
|
|
139
141
|
getFullCommand (opts) {
|
|
140
142
|
const {
|
|
@@ -205,7 +207,7 @@ export class RemoteMessages {
|
|
|
205
207
|
/**
|
|
206
208
|
*
|
|
207
209
|
* @param {import('../types').RemoteCommandOpts & import('../types').ProtocolCommandOpts} opts
|
|
208
|
-
* @returns {import('../types').
|
|
210
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
209
211
|
*/
|
|
210
212
|
getMinimalCommand (opts) {
|
|
211
213
|
const {method, params, connId, senderId, appIdKey, pageIdKey, targetId, id} = opts;
|
|
@@ -244,7 +246,7 @@ export class RemoteMessages {
|
|
|
244
246
|
/**
|
|
245
247
|
*
|
|
246
248
|
* @param {import('../types').RemoteCommandOpts & import('../types').ProtocolCommandOpts} opts
|
|
247
|
-
* @returns {import('../types').
|
|
249
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
248
250
|
*/
|
|
249
251
|
getDirectCommand (opts) {
|
|
250
252
|
const {method, params, connId, senderId, appIdKey, pageIdKey, id} = opts;
|
|
@@ -271,7 +273,7 @@ export class RemoteMessages {
|
|
|
271
273
|
*
|
|
272
274
|
* @param {string} command
|
|
273
275
|
* @param {import('../types').RemoteCommandOpts} opts
|
|
274
|
-
* @returns {import('../types').
|
|
276
|
+
* @returns {import('../types').RawRemoteCommand}
|
|
275
277
|
*/
|
|
276
278
|
getRemoteCommand (command, opts) {
|
|
277
279
|
const {
|
|
@@ -314,8 +316,14 @@ export class RemoteMessages {
|
|
|
314
316
|
|
|
315
317
|
// deal with WebKit commands
|
|
316
318
|
const builderFunction = COMMANDS[command] || MINIMAL_COMMAND;
|
|
319
|
+
const commonOpts = getProtocolCommand(
|
|
320
|
+
/** @type {string} */ (id),
|
|
321
|
+
command,
|
|
322
|
+
opts,
|
|
323
|
+
isDirectCommand(command),
|
|
324
|
+
);
|
|
317
325
|
return this[builderFunction]({
|
|
318
|
-
...
|
|
326
|
+
...commonOpts,
|
|
319
327
|
connId,
|
|
320
328
|
appIdKey,
|
|
321
329
|
senderId,
|
|
@@ -327,4 +335,13 @@ export class RemoteMessages {
|
|
|
327
335
|
// #endregion
|
|
328
336
|
}
|
|
329
337
|
|
|
338
|
+
/**
|
|
339
|
+
*
|
|
340
|
+
* @param {string} command
|
|
341
|
+
* @returns {boolean}
|
|
342
|
+
*/
|
|
343
|
+
export function isDirectCommand (command) {
|
|
344
|
+
return COMMANDS[command] === DIRECT_COMMAND;
|
|
345
|
+
}
|
|
346
|
+
|
|
330
347
|
export default RemoteMessages;
|
|
@@ -25,9 +25,7 @@ export class RpcClientSimulator extends RpcClient {
|
|
|
25
25
|
* @param {import('./rpc-client').RpcClientOptions & RpcClientSimulatorOptions} [opts={}]
|
|
26
26
|
*/
|
|
27
27
|
constructor (opts = {}) {
|
|
28
|
-
super(
|
|
29
|
-
shouldCheckForTarget: false,
|
|
30
|
-
}, opts));
|
|
28
|
+
super(opts);
|
|
31
29
|
|
|
32
30
|
const {
|
|
33
31
|
socketPath,
|