From 10b3edae60013c9379b34689a99da095f61e2c85 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 8 Feb 2024 00:08:47 -0800 Subject: [PATCH] fix: reduce getSession endpoint calls in hybrid mode (#1330) * fix: move getSession command to avoid error in newer chrome * parse platform * fix lint --- app/renderer/actions/Session.js | 6 ++++-- app/renderer/lib/appium-client.js | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/renderer/actions/Session.js b/app/renderer/actions/Session.js index 729e702cf2..b001a2e48c 100644 --- a/app/renderer/actions/Session.js +++ b/app/renderer/actions/Session.js @@ -590,8 +590,10 @@ export function newSession(caps, attachSessId = null) { throw new Error(i18n.t('attachSessionNotRunning', {attachSessId})); } } - serverOpts.isIOS = Boolean(attachedSessionCaps.platformName.match(/iOS/i)); - serverOpts.isAndroid = Boolean(attachedSessionCaps.platformName.match(/Android/i)); + // Chrome MJSONWP mode returns "platform" instead of "platformName" + const platformName = attachedSessionCaps.platformName || attachedSessionCaps.platform; + serverOpts.isIOS = Boolean(platformName.match(/iOS/i)); + serverOpts.isAndroid = Boolean(platformName.match(/Android/i)); driver = await Web2Driver.attachToSession(attachSessId, serverOpts, attachedSessionCaps); driver._isAttachedSession = true; } else { diff --git a/app/renderer/lib/appium-client.js b/app/renderer/lib/appium-client.js index e3659fac04..f3b0601de5 100644 --- a/app/renderer/lib/appium-client.js +++ b/app/renderer/lib/appium-client.js @@ -277,7 +277,6 @@ export default class AppiumClient { await this.driver.switchContext(NATIVE_APP); } - const sessionDetails = await this.driver.getSession(); const isAndroid = this.driver.client.isAndroid; // Get all available contexts (or the error, if one appears) @@ -307,8 +306,12 @@ export default class AppiumClient { const systemBars = await this.driver.executeScript('mobile:getSystemBars', []); webviewTopOffset = systemBars.statusBar.height; } catch (e) { - // in case driver does not support mobile:getSystemBars - webviewTopOffset = sessionDetails.viewportRect.top; + try { + // to minimize the endpoint call which gets error in newer chromedriver. + const sessionDetails = await this.driver.getSession(); + // in case driver does not support mobile:getSystemBars + webviewTopOffset = sessionDetails.viewportRect.top; + } catch (ign) {} } } } else if (this.driver.client.isIOS) { @@ -327,8 +330,11 @@ export default class AppiumClient { const deviceScreenInfo = await this.driver.executeScript('mobile:deviceScreenInfo', []); webviewLeftOffset = deviceScreenInfo.statusBarSize.height; } catch (e) { - // in case driver does not support mobile:deviceScreenInfo - webviewLeftOffset = sessionDetails.statBarHeight; + try { + const sessionDetails = await this.driver.getSession(); + // in case driver does not support mobile:deviceScreenInfo + webviewLeftOffset = sessionDetails.statBarHeight; + } catch (ign) {} } } }