Skip to content

Commit

Permalink
chore: Make remote debugger-related messages more useful (#2443)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Aug 2, 2024
1 parent 855c400 commit 65a5ce1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/commands/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,28 @@ const extensions = {
* @returns {Promise<import('../types').Page[]>}
*/
async listWebFrames(useUrl = true) {
useUrl = useUrl && !this.isRealDevice() && !!this.getCurrentUrl();
const shouldFilterByUrl = useUrl && !this.isRealDevice() && !!this.getCurrentUrl();
this.log.debug(
`Selecting by url: ${useUrl}${useUrl ? ` (expected url: '${this.getCurrentUrl()}')` : ''}`,
`Selecting by url: ${shouldFilterByUrl}` +
(shouldFilterByUrl ? ` (expected url: '${this.getCurrentUrl()}')` : '')
);

if (!this.remote) {
await this.connectToRemoteDebugger();
}
/** @type {number|undefined} */
const maxRetriesCount = this.opts.webviewConnectRetries;
const maxRetriesCount = _.isInteger(this.opts.webviewConnectRetries)
? Math.max(/** @type {number} */ (this.opts.webviewConnectRetries), 1)
: undefined;
this.log.debug(
`About to select a web application with ${util.pluralize('retry', maxRetriesCount ?? 20, true)} ` +
`and 500ms interval between each retry. Consider customizing the value of 'webviewConnectRetries' ` +
`capability to change the amount of retries.`
);
try {
const pageArray = await (/** @type {RemoteDebugger} */ (this.remote)).selectApp(
useUrl ? this.getCurrentUrl() : undefined,
_.isInteger(maxRetriesCount) ? Math.max(/** @type {number} */ (maxRetriesCount), 1) : undefined,
shouldFilterByUrl ? this.getCurrentUrl() : undefined,
maxRetriesCount,
this.opts.ignoreAboutBlankUrl,
);
if (_.isEmpty(pageArray)) {
Expand Down Expand Up @@ -115,9 +123,15 @@ const extensions = {
this.curWebFrames = [];
});

await this.remote.connect(
this.opts.webviewConnectTimeout ?? DEFAULT_REMOTE_DEBUGGER_CONNECT_TIMEOUT_MS
);
const timeoutMs = this.opts.webviewConnectTimeout ?? DEFAULT_REMOTE_DEBUGGER_CONNECT_TIMEOUT_MS;
const apps = await this.remote.connect(timeoutMs);
if (_.isEmpty(apps)) {
this.log.info(
`The remote debugger did not report any active web applications within ${timeoutMs}ms timeout. ` +
`Consider increasing the value of 'webviewConnectTimeout' capability to wait longer ` +
`on slower devices.`
);
}
},

/**
Expand Down

0 comments on commit 65a5ce1

Please sign in to comment.