diff --git a/lib/mixins/connect.js b/lib/mixins/connect.js index 6fcfcc8..3fc5b01 100644 --- a/lib/mixins/connect.js +++ b/lib/mixins/connect.js @@ -211,23 +211,20 @@ async function searchForApp (currentUrl, maxTries, ignoreAboutBlankUrl) { const possibleAppIds = getPossibleDebuggerAppKeys.bind(this)(/** @type {string[]} */ (bundleIds)); this.log.debug(`Trying out the possible app ids: ${possibleAppIds.join(', ')} (try #${retryCount + 1} of ${maxTries})`); for (const attemptedAppIdKey of possibleAppIds) { - try { - if (!getAppDict(this)[attemptedAppIdKey].isActive) { - this.log.debug(`Skipping app '${attemptedAppIdKey}' because it is not active`); - continue; - } + const appInfo = getAppDict(this)[attemptedAppIdKey]; + if (!appInfo) { + continue; + } + if (!appInfo.isActive || (!appInfo.isAutomationEnabled && appInfo.bundleId === SAFARI_BUNDLE_ID)) { + this.log.debug( + `Skipping app '${attemptedAppIdKey}' because it is not ${appInfo.isActive ? 'enabled' : 'active'}` + ); + continue; + } - this.log.debug(`Attempting app '${attemptedAppIdKey}'`); - /** @type {string} */ - let appIdKey; - /** @type {import('@appium/types').StringRecord} */ - let pageDict; - try { - [appIdKey, pageDict] = await this.requireRpcClient().selectApp(attemptedAppIdKey); - } catch (e) { - this.log.info(`Skipping app '${attemptedAppIdKey}'. Original error: ${e.message}`); - continue; - } + this.log.debug(`Attempting app '${attemptedAppIdKey}'`); + try { + const [appIdKey, pageDict] = await this.requireRpcClient().selectApp(attemptedAppIdKey); // save the page array for this app getAppDict(this)[appIdKey].pageArray = pageArrayFromDict(pageDict); diff --git a/lib/mixins/message-handlers.js b/lib/mixins/message-handlers.js index 9f25f7a..c1494b8 100644 --- a/lib/mixins/message-handlers.js +++ b/lib/mixins/message-handlers.js @@ -174,7 +174,7 @@ function updateAppsWithDict (dict) { // get the dictionary entry into a nice form, and add it to the // application dictionary const [id, entry] = appInfoFromDict(dict); - if (getAppDict(this)[id]) { + if (getAppDict(this)[id]?.pageArray) { // preserve the page dictionary for this entry entry.pageArray = getAppDict(this)[id].pageArray; }