Skip to content

Commit

Permalink
fix: Only try to select Safari if it is enabled for automation (#404)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Aug 11, 2024
1 parent 5755433 commit 4621589
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
29 changes: 13 additions & 16 deletions lib/mixins/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/mixins/message-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 4621589

Please sign in to comment.