appium-android-driver 7.8.2 → 8.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.
Files changed (261) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/build/lib/commands/app-management.d.ts +129 -5
  3. package/build/lib/commands/app-management.d.ts.map +1 -1
  4. package/build/lib/commands/app-management.js +433 -128
  5. package/build/lib/commands/app-management.js.map +1 -1
  6. package/build/lib/commands/appearance.d.ts +17 -4
  7. package/build/lib/commands/appearance.d.ts.map +1 -1
  8. package/build/lib/commands/appearance.js +32 -33
  9. package/build/lib/commands/appearance.js.map +1 -1
  10. package/build/lib/commands/context/cache.d.ts +19 -0
  11. package/build/lib/commands/context/cache.d.ts.map +1 -0
  12. package/build/lib/commands/context/cache.js +32 -0
  13. package/build/lib/commands/context/cache.js.map +1 -0
  14. package/build/lib/commands/context/exports.d.ts +141 -0
  15. package/build/lib/commands/context/exports.d.ts.map +1 -0
  16. package/build/lib/commands/context/exports.js +351 -0
  17. package/build/lib/commands/context/exports.js.map +1 -0
  18. package/build/lib/commands/context/helpers.d.ts +98 -0
  19. package/build/lib/commands/context/helpers.d.ts.map +1 -0
  20. package/build/lib/commands/context/helpers.js +715 -0
  21. package/build/lib/commands/context/helpers.js.map +1 -0
  22. package/build/lib/commands/device/common.d.ts +23 -0
  23. package/build/lib/commands/device/common.d.ts.map +1 -0
  24. package/build/lib/commands/device/common.js +230 -0
  25. package/build/lib/commands/device/common.js.map +1 -0
  26. package/build/lib/commands/device/emulator-actions.d.ts +114 -0
  27. package/build/lib/commands/device/emulator-actions.d.ts.map +1 -0
  28. package/build/lib/commands/device/emulator-actions.js +197 -0
  29. package/build/lib/commands/device/emulator-actions.js.map +1 -0
  30. package/build/lib/commands/device/emulator-console.d.ts +7 -0
  31. package/build/lib/commands/device/emulator-console.d.ts.map +1 -0
  32. package/build/lib/commands/device/emulator-console.js +24 -0
  33. package/build/lib/commands/device/emulator-console.js.map +1 -0
  34. package/build/lib/commands/device/utils.d.ts +50 -0
  35. package/build/lib/commands/device/utils.d.ts.map +1 -0
  36. package/build/lib/commands/device/utils.js +238 -0
  37. package/build/lib/commands/device/utils.js.map +1 -0
  38. package/build/lib/commands/deviceidle.d.ts +8 -5
  39. package/build/lib/commands/deviceidle.d.ts.map +1 -1
  40. package/build/lib/commands/deviceidle.js +31 -37
  41. package/build/lib/commands/deviceidle.js.map +1 -1
  42. package/build/lib/commands/element.d.ts +99 -5
  43. package/build/lib/commands/element.d.ts.map +1 -1
  44. package/build/lib/commands/element.js +152 -116
  45. package/build/lib/commands/element.js.map +1 -1
  46. package/build/lib/commands/execute.d.ts +12 -4
  47. package/build/lib/commands/execute.d.ts.map +1 -1
  48. package/build/lib/commands/execute.js +83 -78
  49. package/build/lib/commands/execute.js.map +1 -1
  50. package/build/lib/commands/file-actions.d.ts +42 -5
  51. package/build/lib/commands/file-actions.d.ts.map +1 -1
  52. package/build/lib/commands/file-actions.js +230 -194
  53. package/build/lib/commands/file-actions.js.map +1 -1
  54. package/build/lib/commands/find.d.ts +5 -4
  55. package/build/lib/commands/find.d.ts.map +1 -1
  56. package/build/lib/commands/find.js +7 -10
  57. package/build/lib/commands/find.js.map +1 -1
  58. package/build/lib/commands/geolocation.d.ts +45 -0
  59. package/build/lib/commands/geolocation.d.ts.map +1 -0
  60. package/build/lib/commands/geolocation.js +182 -0
  61. package/build/lib/commands/geolocation.js.map +1 -0
  62. package/build/lib/commands/ime.d.ts +25 -5
  63. package/build/lib/commands/ime.d.ts.map +1 -1
  64. package/build/lib/commands/ime.js +59 -42
  65. package/build/lib/commands/ime.js.map +1 -1
  66. package/build/lib/commands/intent.d.ts +56 -5
  67. package/build/lib/commands/intent.d.ts.map +1 -1
  68. package/build/lib/commands/intent.js +135 -83
  69. package/build/lib/commands/intent.js.map +1 -1
  70. package/build/lib/commands/keyboard.d.ts +58 -4
  71. package/build/lib/commands/keyboard.d.ts.map +1 -1
  72. package/build/lib/commands/keyboard.js +119 -17
  73. package/build/lib/commands/keyboard.js.map +1 -1
  74. package/build/lib/commands/lock/exports.d.ts +301 -0
  75. package/build/lib/commands/lock/exports.d.ts.map +1 -0
  76. package/build/lib/commands/lock/exports.js +121 -0
  77. package/build/lib/commands/lock/exports.js.map +1 -0
  78. package/build/lib/commands/lock/helpers.d.ts +349 -0
  79. package/build/lib/commands/lock/helpers.d.ts.map +1 -0
  80. package/build/lib/commands/lock/helpers.js +375 -0
  81. package/build/lib/commands/lock/helpers.js.map +1 -0
  82. package/build/lib/commands/log.d.ts +59 -5
  83. package/build/lib/commands/log.d.ts.map +1 -1
  84. package/build/lib/commands/log.js +150 -140
  85. package/build/lib/commands/log.js.map +1 -1
  86. package/build/lib/commands/media-projection.d.ts +16 -5
  87. package/build/lib/commands/media-projection.d.ts.map +1 -1
  88. package/build/lib/commands/media-projection.js +69 -58
  89. package/build/lib/commands/media-projection.js.map +1 -1
  90. package/build/lib/commands/memory.d.ts +9 -5
  91. package/build/lib/commands/memory.d.ts.map +1 -1
  92. package/build/lib/commands/memory.js +19 -24
  93. package/build/lib/commands/memory.js.map +1 -1
  94. package/build/lib/commands/misc.d.ts +42 -0
  95. package/build/lib/commands/misc.d.ts.map +1 -0
  96. package/build/lib/commands/misc.js +100 -0
  97. package/build/lib/commands/misc.js.map +1 -0
  98. package/build/lib/commands/network.d.ts +61 -5
  99. package/build/lib/commands/network.d.ts.map +1 -1
  100. package/build/lib/commands/network.js +196 -189
  101. package/build/lib/commands/network.js.map +1 -1
  102. package/build/lib/commands/performance.d.ts +67 -27
  103. package/build/lib/commands/performance.d.ts.map +1 -1
  104. package/build/lib/commands/performance.js +105 -80
  105. package/build/lib/commands/performance.js.map +1 -1
  106. package/build/lib/commands/permissions.d.ts +12 -6
  107. package/build/lib/commands/permissions.d.ts.map +1 -1
  108. package/build/lib/commands/permissions.js +65 -62
  109. package/build/lib/commands/permissions.js.map +1 -1
  110. package/build/lib/commands/recordscreen.d.ts +44 -5
  111. package/build/lib/commands/recordscreen.d.ts.map +1 -1
  112. package/build/lib/commands/recordscreen.js +131 -126
  113. package/build/lib/commands/recordscreen.js.map +1 -1
  114. package/build/lib/commands/resources.d.ts +16 -0
  115. package/build/lib/commands/resources.d.ts.map +1 -0
  116. package/build/lib/commands/resources.js +91 -0
  117. package/build/lib/commands/resources.js.map +1 -0
  118. package/build/lib/commands/shell.d.ts +8 -5
  119. package/build/lib/commands/shell.d.ts.map +1 -1
  120. package/build/lib/commands/shell.js +29 -33
  121. package/build/lib/commands/shell.js.map +1 -1
  122. package/build/lib/commands/streamscreen.d.ts +34 -6
  123. package/build/lib/commands/streamscreen.d.ts.map +1 -1
  124. package/build/lib/commands/streamscreen.js +166 -162
  125. package/build/lib/commands/streamscreen.js.map +1 -1
  126. package/build/lib/commands/system-bars.d.ts +18 -13
  127. package/build/lib/commands/system-bars.d.ts.map +1 -1
  128. package/build/lib/commands/system-bars.js +68 -64
  129. package/build/lib/commands/system-bars.js.map +1 -1
  130. package/build/lib/commands/time.d.ts +14 -0
  131. package/build/lib/commands/time.d.ts.map +1 -0
  132. package/build/lib/commands/time.js +39 -0
  133. package/build/lib/commands/time.js.map +1 -0
  134. package/build/lib/commands/touch.d.ts +99 -6
  135. package/build/lib/commands/touch.d.ts.map +1 -1
  136. package/build/lib/commands/touch.js +399 -280
  137. package/build/lib/commands/touch.js.map +1 -1
  138. package/build/lib/commands/types.d.ts +115 -3
  139. package/build/lib/commands/types.d.ts.map +1 -1
  140. package/build/lib/doctor/checks.d.ts.map +1 -1
  141. package/build/lib/doctor/checks.js +4 -4
  142. package/build/lib/doctor/checks.js.map +1 -1
  143. package/build/lib/driver.d.ts +224 -27
  144. package/build/lib/driver.d.ts.map +1 -1
  145. package/build/lib/driver.js +232 -7
  146. package/build/lib/driver.js.map +1 -1
  147. package/build/lib/index.d.ts +1 -4
  148. package/build/lib/index.d.ts.map +1 -1
  149. package/build/lib/index.js +1 -13
  150. package/build/lib/index.js.map +1 -1
  151. package/build/lib/logger.js.map +1 -1
  152. package/build/lib/method-map.d.ts +0 -23
  153. package/build/lib/method-map.d.ts.map +1 -1
  154. package/build/lib/method-map.js +0 -11
  155. package/build/lib/method-map.js.map +1 -1
  156. package/build/lib/utils.d.ts +12 -0
  157. package/build/lib/utils.d.ts.map +1 -1
  158. package/build/lib/utils.js +38 -2
  159. package/build/lib/utils.js.map +1 -1
  160. package/lib/commands/app-management.js +470 -145
  161. package/lib/commands/appearance.js +29 -36
  162. package/lib/commands/context/cache.js +29 -0
  163. package/lib/commands/context/exports.js +379 -0
  164. package/lib/commands/context/helpers.js +802 -0
  165. package/lib/commands/device/common.js +264 -0
  166. package/lib/commands/device/emulator-actions.js +194 -0
  167. package/lib/commands/device/emulator-console.js +24 -0
  168. package/lib/commands/device/utils.js +285 -0
  169. package/lib/commands/deviceidle.js +31 -44
  170. package/lib/commands/element.js +149 -142
  171. package/lib/commands/execute.js +86 -87
  172. package/lib/commands/file-actions.js +249 -222
  173. package/lib/commands/find.ts +13 -19
  174. package/lib/commands/geolocation.js +179 -0
  175. package/lib/commands/ime.js +53 -45
  176. package/lib/commands/intent.js +149 -91
  177. package/lib/commands/keyboard.js +114 -17
  178. package/lib/commands/lock/exports.js +139 -0
  179. package/lib/commands/lock/helpers.js +379 -0
  180. package/lib/commands/log.js +170 -166
  181. package/lib/commands/media-projection.js +75 -70
  182. package/lib/commands/memory.js +17 -29
  183. package/lib/commands/misc.js +94 -0
  184. package/lib/commands/network.js +209 -223
  185. package/lib/commands/performance.js +88 -73
  186. package/lib/commands/permissions.js +83 -84
  187. package/lib/commands/recordscreen.js +171 -170
  188. package/lib/commands/resources.js +96 -0
  189. package/lib/commands/shell.js +28 -42
  190. package/lib/commands/streamscreen.js +207 -206
  191. package/lib/commands/system-bars.js +76 -77
  192. package/lib/commands/time.js +36 -0
  193. package/lib/commands/touch.js +442 -346
  194. package/lib/commands/types.ts +142 -10
  195. package/lib/doctor/checks.js +24 -16
  196. package/lib/driver.ts +454 -12
  197. package/lib/index.ts +1 -13
  198. package/lib/logger.js +1 -1
  199. package/lib/method-map.js +0 -11
  200. package/lib/utils.js +40 -3
  201. package/package.json +1 -1
  202. package/build/lib/commands/actions.d.ts +0 -8
  203. package/build/lib/commands/actions.d.ts.map +0 -1
  204. package/build/lib/commands/actions.js +0 -207
  205. package/build/lib/commands/actions.js.map +0 -1
  206. package/build/lib/commands/alert.d.ts +0 -8
  207. package/build/lib/commands/alert.d.ts.map +0 -1
  208. package/build/lib/commands/alert.js +0 -29
  209. package/build/lib/commands/alert.js.map +0 -1
  210. package/build/lib/commands/context.d.ts +0 -10
  211. package/build/lib/commands/context.d.ts.map +0 -1
  212. package/build/lib/commands/context.js +0 -431
  213. package/build/lib/commands/context.js.map +0 -1
  214. package/build/lib/commands/emu-console.d.ts +0 -7
  215. package/build/lib/commands/emu-console.d.ts.map +0 -1
  216. package/build/lib/commands/emu-console.js +0 -27
  217. package/build/lib/commands/emu-console.js.map +0 -1
  218. package/build/lib/commands/general.d.ts +0 -9
  219. package/build/lib/commands/general.d.ts.map +0 -1
  220. package/build/lib/commands/general.js +0 -293
  221. package/build/lib/commands/general.js.map +0 -1
  222. package/build/lib/commands/index.d.ts +0 -28
  223. package/build/lib/commands/index.d.ts.map +0 -1
  224. package/build/lib/commands/index.js +0 -57
  225. package/build/lib/commands/index.js.map +0 -1
  226. package/build/lib/commands/mixins.d.ts +0 -747
  227. package/build/lib/commands/mixins.d.ts.map +0 -1
  228. package/build/lib/commands/mixins.js +0 -19
  229. package/build/lib/commands/mixins.js.map +0 -1
  230. package/build/lib/helpers/android.d.ts +0 -163
  231. package/build/lib/helpers/android.d.ts.map +0 -1
  232. package/build/lib/helpers/android.js +0 -818
  233. package/build/lib/helpers/android.js.map +0 -1
  234. package/build/lib/helpers/index.d.ts +0 -7
  235. package/build/lib/helpers/index.d.ts.map +0 -1
  236. package/build/lib/helpers/index.js +0 -29
  237. package/build/lib/helpers/index.js.map +0 -1
  238. package/build/lib/helpers/types.d.ts +0 -122
  239. package/build/lib/helpers/types.d.ts.map +0 -1
  240. package/build/lib/helpers/types.js +0 -3
  241. package/build/lib/helpers/types.js.map +0 -1
  242. package/build/lib/helpers/unlock.d.ts +0 -32
  243. package/build/lib/helpers/unlock.d.ts.map +0 -1
  244. package/build/lib/helpers/unlock.js +0 -273
  245. package/build/lib/helpers/unlock.js.map +0 -1
  246. package/build/lib/helpers/webview.d.ts +0 -74
  247. package/build/lib/helpers/webview.d.ts.map +0 -1
  248. package/build/lib/helpers/webview.js +0 -442
  249. package/build/lib/helpers/webview.js.map +0 -1
  250. package/lib/commands/actions.js +0 -244
  251. package/lib/commands/alert.js +0 -34
  252. package/lib/commands/context.js +0 -507
  253. package/lib/commands/emu-console.js +0 -31
  254. package/lib/commands/general.js +0 -343
  255. package/lib/commands/index.ts +0 -54
  256. package/lib/commands/mixins.ts +0 -976
  257. package/lib/helpers/android.ts +0 -1153
  258. package/lib/helpers/index.ts +0 -6
  259. package/lib/helpers/types.ts +0 -136
  260. package/lib/helpers/unlock.ts +0 -329
  261. package/lib/helpers/webview.ts +0 -604
@@ -0,0 +1,715 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dismissChromeWelcome = exports.shouldDismissChromeWelcome = exports.setupExistingChromedriver = exports.setupNewChromedriver = exports.getWebViewsMapping = exports.parseWebviewNames = exports.getChromePkg = exports.DEVTOOLS_SOCKET_PATTERN = exports.WEBVIEW_BASE = exports.CHROMIUM_WIN = exports.WEBVIEW_WIN = exports.NATIVE_WIN = exports.KNOWN_CHROME_PACKAGE_NAMES = exports.CHROME_PACKAGE_NAME = exports.CHROME_BROWSER_PACKAGE_ACTIVITY = void 0;
7
+ const support_1 = require("@appium/support");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const axios_1 = __importDefault(require("axios"));
10
+ const node_net_1 = __importDefault(require("node:net"));
11
+ const portscanner_1 = require("portscanner");
12
+ const asyncbox_1 = require("asyncbox");
13
+ const bluebird_1 = __importDefault(require("bluebird"));
14
+ const node_os_1 = __importDefault(require("node:os"));
15
+ const node_path_1 = __importDefault(require("node:path"));
16
+ const node_http_1 = __importDefault(require("node:http"));
17
+ const appium_chromedriver_1 = __importDefault(require("appium-chromedriver"));
18
+ const cache_1 = require("./cache");
19
+ // https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc
20
+ exports.CHROME_BROWSER_PACKAGE_ACTIVITY = ({
21
+ chrome: {
22
+ pkg: 'com.android.chrome',
23
+ activity: 'com.google.android.apps.chrome.Main',
24
+ },
25
+ chromium: {
26
+ pkg: 'org.chromium.chrome.shell',
27
+ activity: '.ChromeShellActivity',
28
+ },
29
+ chromebeta: {
30
+ pkg: 'com.chrome.beta',
31
+ activity: 'com.google.android.apps.chrome.Main',
32
+ },
33
+ browser: {
34
+ pkg: 'com.android.browser',
35
+ activity: 'com.android.browser.BrowserActivity',
36
+ },
37
+ 'chromium-browser': {
38
+ pkg: 'org.chromium.chrome',
39
+ activity: 'com.google.android.apps.chrome.Main',
40
+ },
41
+ 'chromium-webview': {
42
+ pkg: 'org.chromium.webview_shell',
43
+ activity: 'org.chromium.webview_shell.WebViewBrowserActivity',
44
+ },
45
+ default: {
46
+ pkg: 'com.android.chrome',
47
+ activity: 'com.google.android.apps.chrome.Main',
48
+ },
49
+ });
50
+ exports.CHROME_PACKAGE_NAME = 'com.android.chrome';
51
+ exports.KNOWN_CHROME_PACKAGE_NAMES = [
52
+ exports.CHROME_PACKAGE_NAME,
53
+ 'com.chrome.beta',
54
+ 'com.chrome.dev',
55
+ 'com.chrome.canary',
56
+ ];
57
+ const CHROMEDRIVER_AUTODOWNLOAD_FEATURE = 'chromedriver_autodownload';
58
+ const CROSSWALK_SOCKET_PATTERN = /@([\w.]+)_devtools_remote\b/;
59
+ const CHROMIUM_DEVTOOLS_SOCKET = 'chrome_devtools_remote';
60
+ exports.NATIVE_WIN = 'NATIVE_APP';
61
+ exports.WEBVIEW_WIN = 'WEBVIEW';
62
+ exports.CHROMIUM_WIN = 'CHROMIUM';
63
+ exports.WEBVIEW_BASE = `${exports.WEBVIEW_WIN}_`;
64
+ exports.DEVTOOLS_SOCKET_PATTERN = /@[\w.]+_devtools_remote_?([\w.]+_)?(\d+)?\b/;
65
+ const WEBVIEW_PID_PATTERN = new RegExp(`^${exports.WEBVIEW_BASE}(\\d+)`);
66
+ const WEBVIEW_PKG_PATTERN = new RegExp(`^${exports.WEBVIEW_BASE}([^\\d\\s][\\w.]*)`);
67
+ const WEBVIEW_WAIT_INTERVAL_MS = 200;
68
+ const CDP_REQ_TIMEOUT = 2000; // ms
69
+ const DEVTOOLS_PORTS_RANGE = [10900, 11000];
70
+ const DEVTOOLS_PORT_ALLOCATION_GUARD = support_1.util.getLockFileGuard(node_path_1.default.resolve(node_os_1.default.tmpdir(), 'android_devtools_port_guard'), { timeout: 7, tryRecovery: true });
71
+ /**
72
+ * @returns {Promise<number>}
73
+ */
74
+ async function getFreePort() {
75
+ return await new Promise((resolve, reject) => {
76
+ const srv = node_net_1.default.createServer();
77
+ srv.listen(0, () => {
78
+ const address = srv.address();
79
+ let port;
80
+ if (lodash_1.default.has(address, 'port')) {
81
+ // @ts-ignore The above condition covers possible errors
82
+ port = address.port;
83
+ }
84
+ else {
85
+ reject(new Error('Cannot determine any free port number'));
86
+ }
87
+ srv.close(() => resolve(port));
88
+ });
89
+ });
90
+ }
91
+ /**
92
+ * https://chromedevtools.github.io/devtools-protocol/
93
+ *
94
+ * @param {string} host
95
+ * @param {number} port
96
+ * @param {string} endpoint
97
+ * @returns {Promise<object[]>}
98
+ */
99
+ async function cdpGetRequest(host, port, endpoint) {
100
+ return (await (0, axios_1.default)({
101
+ url: `http://${host}:${port}${endpoint}`,
102
+ timeout: CDP_REQ_TIMEOUT,
103
+ // We need to set this from Node.js v19 onwards.
104
+ // Otherwise, in situation with multiple webviews,
105
+ // the preceding webview pages will be incorrectly retrieved as the current ones.
106
+ // https://nodejs.org/en/blog/announcements/v19-release-announce#https11-keepalive-by-default
107
+ httpAgent: new node_http_1.default.Agent({ keepAlive: false }),
108
+ })).data;
109
+ }
110
+ /**
111
+ * @param {string} host
112
+ * @param {number} port
113
+ * @returns {Promise<object[]>}
114
+ */
115
+ async function cdpList(host, port) {
116
+ return cdpGetRequest(host, port, '/json/list');
117
+ }
118
+ /**
119
+ * @param {string} host
120
+ * @param {number} port
121
+ * @returns {Promise<object[]>}
122
+ */
123
+ async function cdpInfo(host, port) {
124
+ return cdpGetRequest(host, port, '/json/version');
125
+ }
126
+ /**
127
+ *
128
+ * @param {string} browser
129
+ * @returns {import('type-fest').ValueOf<typeof CHROME_BROWSER_PACKAGE_ACTIVITY>}
130
+ */
131
+ function getChromePkg(browser) {
132
+ return (exports.CHROME_BROWSER_PACKAGE_ACTIVITY[browser.toLowerCase()] ||
133
+ exports.CHROME_BROWSER_PACKAGE_ACTIVITY.default);
134
+ }
135
+ exports.getChromePkg = getChromePkg;
136
+ /**
137
+ * Create Chromedriver capabilities based on the provided
138
+ * Appium capabilities
139
+ *
140
+ * @this {import('../../driver').AndroidDriver}
141
+ * @param {any} opts
142
+ * @param {string} deviceId
143
+ * @param {import('../types').WebViewDetails | null} [webViewDetails]
144
+ * @returns {import('@appium/types').StringRecord}
145
+ */
146
+ function createChromedriverCaps(opts, deviceId, webViewDetails) {
147
+ const caps = { chromeOptions: {} };
148
+ const androidPackage = opts.chromeOptions?.androidPackage ||
149
+ opts.appPackage ||
150
+ webViewDetails?.info?.['Android-Package'];
151
+ if (androidPackage) {
152
+ // chromedriver raises an invalid argument error when androidPackage is 'null'
153
+ caps.chromeOptions.androidPackage = androidPackage;
154
+ }
155
+ if (lodash_1.default.isBoolean(opts.chromeUseRunningApp)) {
156
+ caps.chromeOptions.androidUseRunningApp = opts.chromeUseRunningApp;
157
+ }
158
+ if (opts.chromeAndroidPackage) {
159
+ caps.chromeOptions.androidPackage = opts.chromeAndroidPackage;
160
+ }
161
+ if (opts.chromeAndroidActivity) {
162
+ caps.chromeOptions.androidActivity = opts.chromeAndroidActivity;
163
+ }
164
+ if (opts.chromeAndroidProcess) {
165
+ caps.chromeOptions.androidProcess = opts.chromeAndroidProcess;
166
+ }
167
+ else if (webViewDetails?.process?.name && webViewDetails?.process?.id) {
168
+ caps.chromeOptions.androidProcess = webViewDetails.process.name;
169
+ }
170
+ if (lodash_1.default.toLower(opts.browserName) === 'chromium-webview') {
171
+ caps.chromeOptions.androidActivity = opts.appActivity;
172
+ }
173
+ if (opts.pageLoadStrategy) {
174
+ caps.pageLoadStrategy = opts.pageLoadStrategy;
175
+ }
176
+ const isChrome = lodash_1.default.toLower(caps.chromeOptions.androidPackage) === 'chrome';
177
+ if (lodash_1.default.includes(exports.KNOWN_CHROME_PACKAGE_NAMES, caps.chromeOptions.androidPackage) || isChrome) {
178
+ // if we have extracted package from context name, it could come in as bare
179
+ // "chrome", and so we should make sure the details are correct, including
180
+ // not using an activity or process id
181
+ if (isChrome) {
182
+ caps.chromeOptions.androidPackage = exports.CHROME_PACKAGE_NAME;
183
+ }
184
+ delete caps.chromeOptions.androidActivity;
185
+ delete caps.chromeOptions.androidProcess;
186
+ }
187
+ // add device id from adb
188
+ caps.chromeOptions.androidDeviceSerial = deviceId;
189
+ if (lodash_1.default.isPlainObject(opts.loggingPrefs) || lodash_1.default.isPlainObject(opts.chromeLoggingPrefs)) {
190
+ if (opts.loggingPrefs) {
191
+ this.log.warn(`The 'loggingPrefs' cap is deprecated; use the 'chromeLoggingPrefs' cap instead`);
192
+ }
193
+ caps.loggingPrefs = opts.chromeLoggingPrefs || opts.loggingPrefs;
194
+ }
195
+ if (opts.enablePerformanceLogging) {
196
+ this.log.warn(`The 'enablePerformanceLogging' cap is deprecated; simply use ` +
197
+ `the 'chromeLoggingPrefs' cap instead, with a 'performance' key set to 'ALL'`);
198
+ const newPref = { performance: 'ALL' };
199
+ // don't overwrite other logging prefs that have been sent in if they exist
200
+ caps.loggingPrefs = caps.loggingPrefs ? Object.assign({}, caps.loggingPrefs, newPref) : newPref;
201
+ }
202
+ if (opts.chromeOptions?.Arguments) {
203
+ // merge `Arguments` and `args`
204
+ opts.chromeOptions.args = [...(opts.chromeOptions.args || []), ...opts.chromeOptions.Arguments];
205
+ delete opts.chromeOptions.Arguments;
206
+ }
207
+ this.log.debug('Precalculated Chromedriver capabilities: ' + JSON.stringify(caps.chromeOptions, null, 2));
208
+ /** @type {string[]} */
209
+ const protectedCapNames = [];
210
+ for (const [opt, val] of lodash_1.default.toPairs(opts.chromeOptions)) {
211
+ if (lodash_1.default.isUndefined(caps.chromeOptions[opt])) {
212
+ caps.chromeOptions[opt] = val;
213
+ }
214
+ else {
215
+ protectedCapNames.push(opt);
216
+ }
217
+ }
218
+ if (!lodash_1.default.isEmpty(protectedCapNames)) {
219
+ this.log.info('The following Chromedriver capabilities cannot be overridden ' +
220
+ 'by the provided chromeOptions:');
221
+ for (const optName of protectedCapNames) {
222
+ this.log.info(` ${optName} (${JSON.stringify(opts.chromeOptions[optName])})`);
223
+ }
224
+ }
225
+ return caps;
226
+ }
227
+ /**
228
+ * Parse webview names for getContexts
229
+ *
230
+ * @this {import('../../driver').AndroidDriver}
231
+ * @param {import('../types').WebviewsMapping[]} webviewsMapping
232
+ * @param {import('../types').GetWebviewsOpts} options
233
+ * @returns {string[]}
234
+ */
235
+ function parseWebviewNames(webviewsMapping, { ensureWebviewsHavePages = true, isChromeSession = false } = {}) {
236
+ if (isChromeSession) {
237
+ return [exports.CHROMIUM_WIN];
238
+ }
239
+ /** @type {string[]} */
240
+ const result = [];
241
+ for (const { webview, pages, proc, webviewName } of webviewsMapping) {
242
+ if (ensureWebviewsHavePages && !pages?.length) {
243
+ this.log.info(`Skipping the webview '${webview}' at '${proc}' ` +
244
+ `since it has reported having zero pages`);
245
+ continue;
246
+ }
247
+ if (webviewName) {
248
+ result.push(webviewName);
249
+ }
250
+ }
251
+ this.log.debug(`Found ${support_1.util.pluralize('webview', result.length, true)}: ${JSON.stringify(result)}`);
252
+ return result;
253
+ }
254
+ exports.parseWebviewNames = parseWebviewNames;
255
+ /**
256
+ * Allocates a local port for devtools communication
257
+ *
258
+ * @this {import('../../driver').AndroidDriver}
259
+ * @param {string} socketName - The remote Unix socket name
260
+ * @param {number?} [webviewDevtoolsPort=null] - The local port number or null to apply
261
+ * autodetection
262
+ * @returns {Promise<[string, number]>} The host name and the port number to connect to if the
263
+ * remote socket has been forwarded successfully
264
+ * @throws {Error} If there was an error while allocating the local port
265
+ */
266
+ async function allocateDevtoolsChannel(socketName, webviewDevtoolsPort = null) {
267
+ // socket names come with '@', but this should not be a part of the abstract
268
+ // remote port, so remove it
269
+ const remotePort = socketName.replace(/^@/, '');
270
+ let [startPort, endPort] = DEVTOOLS_PORTS_RANGE;
271
+ if (webviewDevtoolsPort) {
272
+ endPort = webviewDevtoolsPort + (endPort - startPort);
273
+ startPort = webviewDevtoolsPort;
274
+ }
275
+ this.log.debug(`Forwarding remote port ${remotePort} to a local ` + `port in range ${startPort}..${endPort}`);
276
+ if (!webviewDevtoolsPort) {
277
+ this.log.debug(`You could use the 'webviewDevtoolsPort' capability to customize ` +
278
+ `the starting port number`);
279
+ }
280
+ const port = await DEVTOOLS_PORT_ALLOCATION_GUARD(async () => {
281
+ let localPort;
282
+ try {
283
+ localPort = await (0, portscanner_1.findAPortNotInUse)(startPort, endPort);
284
+ }
285
+ catch (e) {
286
+ throw new Error(`Cannot find any free port to forward the Devtools socket ` +
287
+ `in range ${startPort}..${endPort}. You could set the starting port number ` +
288
+ `manually by providing the 'webviewDevtoolsPort' capability`);
289
+ }
290
+ await this.adb.adbExec(['forward', `tcp:${localPort}`, `localabstract:${remotePort}`]);
291
+ return localPort;
292
+ });
293
+ return [this.adb.adbHost ?? '127.0.0.1', port];
294
+ }
295
+ /**
296
+ * This is a wrapper for Chrome Debugger Protocol data collection.
297
+ * No error is thrown if CDP request fails - in such case no data will be
298
+ * recorded into the corresponding `webviewsMapping` item.
299
+ *
300
+ * @this {import('../../driver').AndroidDriver}
301
+ * @param {import('../types').WebviewProps[]} webviewsMapping The current webviews mapping
302
+ * !!! Each item of this array gets mutated (`info`/`pages` properties get added
303
+ * based on the provided `opts`) if the requested details have been
304
+ * successfully retrieved for it !!!
305
+ * @param {import('../types').DetailCollectionOptions} [opts={}] If both `ensureWebviewsHavePages` and
306
+ * `enableWebviewDetailsCollection` properties are falsy then no details collection
307
+ * is performed
308
+ * @returns {Promise<void>}
309
+ */
310
+ async function collectWebviewsDetails(webviewsMapping, opts = {}) {
311
+ if (lodash_1.default.isEmpty(webviewsMapping)) {
312
+ return;
313
+ }
314
+ const { webviewDevtoolsPort = null, ensureWebviewsHavePages = null, enableWebviewDetailsCollection = null, } = opts;
315
+ if (!ensureWebviewsHavePages) {
316
+ this.log.info(`Not checking whether webviews have active pages; use the ` +
317
+ `'ensureWebviewsHavePages' cap to turn this check on`);
318
+ }
319
+ if (!enableWebviewDetailsCollection) {
320
+ this.log.info(`Not collecting web view details. Details collection might help ` +
321
+ `to make Chromedriver initialization more precise. Use the 'enableWebviewDetailsCollection' ` +
322
+ `cap to turn it on`);
323
+ }
324
+ if (!ensureWebviewsHavePages && !enableWebviewDetailsCollection) {
325
+ return;
326
+ }
327
+ // Connect to each devtools socket and retrieve web view details
328
+ this.log.debug(`Collecting CDP data of ${support_1.util.pluralize('webview', webviewsMapping.length, true)}`);
329
+ const detailCollectors = [];
330
+ for (const item of webviewsMapping) {
331
+ detailCollectors.push((async () => {
332
+ let port;
333
+ let host;
334
+ try {
335
+ [host, port] = await allocateDevtoolsChannel.bind(this)(item.proc, webviewDevtoolsPort);
336
+ if (enableWebviewDetailsCollection) {
337
+ item.info = await cdpInfo(host, port);
338
+ }
339
+ if (ensureWebviewsHavePages) {
340
+ item.pages = await cdpList(host, port);
341
+ }
342
+ }
343
+ catch (e) {
344
+ this.log.debug(e);
345
+ }
346
+ finally {
347
+ if (port) {
348
+ try {
349
+ await this.adb.removePortForward(port);
350
+ }
351
+ catch (e) {
352
+ this.log.debug(e);
353
+ }
354
+ }
355
+ }
356
+ })());
357
+ }
358
+ await bluebird_1.default.all(detailCollectors);
359
+ this.log.debug(`CDP data collection completed`);
360
+ }
361
+ /**
362
+ * Get a list of available webviews mapping by introspecting processes with adb,
363
+ * where webviews are listed. It's possible to pass in a 'deviceSocket' arg, which
364
+ * limits the webview possibilities to the one running on the Chromium devtools
365
+ * socket we're interested in (see note on webviewsFromProcs). We can also
366
+ * direct this method to verify whether a particular webview process actually
367
+ * has any pages (if a process exists but no pages are found, Chromedriver will
368
+ * not actually be able to connect to it, so this serves as a guard for that
369
+ * strange failure mode). The strategy for checking whether any pages are
370
+ * active involves sending a request to the remote debug server on the device,
371
+ * hence it is also possible to specify the port on the host machine which
372
+ * should be used for this communication.
373
+ *
374
+ * @this {import('../../driver').AndroidDriver}
375
+ * @param {import('../types').GetWebviewsOpts} [opts={}]
376
+ * @returns {Promise<import('../types').WebviewsMapping[]>}
377
+ */
378
+ async function getWebViewsMapping({ androidDeviceSocket = null, ensureWebviewsHavePages = true, webviewDevtoolsPort = null, enableWebviewDetailsCollection = true, waitForWebviewMs = 0, } = {}) {
379
+ this.log.debug(`Getting a list of available webviews`);
380
+ if (!lodash_1.default.isNumber(waitForWebviewMs)) {
381
+ waitForWebviewMs = parseInt(`${waitForWebviewMs}`, 10) || 0;
382
+ }
383
+ /** @type {import('../types').WebviewsMapping[]} */
384
+ let webviewsMapping;
385
+ const timer = new support_1.timing.Timer().start();
386
+ do {
387
+ webviewsMapping = await webviewsFromProcs.bind(this)(androidDeviceSocket);
388
+ if (webviewsMapping.length > 0) {
389
+ break;
390
+ }
391
+ this.log.debug(`No webviews found in ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);
392
+ await (0, asyncbox_1.sleep)(WEBVIEW_WAIT_INTERVAL_MS);
393
+ } while (timer.getDuration().asMilliSeconds < waitForWebviewMs);
394
+ await collectWebviewsDetails.bind(this)(webviewsMapping, {
395
+ ensureWebviewsHavePages,
396
+ enableWebviewDetailsCollection,
397
+ webviewDevtoolsPort,
398
+ });
399
+ for (const webviewMapping of webviewsMapping) {
400
+ const { webview, info } = webviewMapping;
401
+ webviewMapping.webviewName = null;
402
+ let wvName = webview;
403
+ /** @type {{name: string; id: string | null} | undefined} */
404
+ let process;
405
+ if (!androidDeviceSocket) {
406
+ const pkgMatch = WEBVIEW_PKG_PATTERN.exec(webview);
407
+ try {
408
+ // web view name could either be suffixed with PID or the package name
409
+ // package names could not start with a digit
410
+ const pkg = pkgMatch ? pkgMatch[1] : await procFromWebview.bind(this)(webview);
411
+ wvName = `${exports.WEBVIEW_BASE}${pkg}`;
412
+ const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);
413
+ process = {
414
+ name: pkg,
415
+ id: pidMatch ? pidMatch[1] : null,
416
+ };
417
+ }
418
+ catch (e) {
419
+ this.log.debug(e.stack);
420
+ this.log.warn(e.message);
421
+ continue;
422
+ }
423
+ }
424
+ webviewMapping.webviewName = wvName;
425
+ const key = (0, cache_1.toDetailsCacheKey)(this.adb, wvName);
426
+ if (info || process) {
427
+ cache_1.WEBVIEWS_DETAILS_CACHE.set(key, { info, process });
428
+ }
429
+ else if (cache_1.WEBVIEWS_DETAILS_CACHE.has(key)) {
430
+ cache_1.WEBVIEWS_DETAILS_CACHE.delete(key);
431
+ }
432
+ }
433
+ return webviewsMapping;
434
+ }
435
+ exports.getWebViewsMapping = getWebViewsMapping;
436
+ /**
437
+ * Take a webview name like WEBVIEW_4296 and use 'adb shell ps' to figure out
438
+ * which app package is associated with that webview. One of the reasons we
439
+ * want to do this is to make sure we're listing webviews for the actual AUT,
440
+ * not some other running app
441
+ *
442
+ * @this {import('../../driver').AndroidDriver}
443
+ * @param {string} webview
444
+ * @returns {Promise<string>}
445
+ */
446
+ async function procFromWebview(webview) {
447
+ const pidMatch = WEBVIEW_PID_PATTERN.exec(webview);
448
+ if (!pidMatch) {
449
+ throw new Error(`Could not find PID for webview '${webview}'`);
450
+ }
451
+ const pid = pidMatch[1];
452
+ this.log.debug(`${webview} mapped to pid ${pid}`);
453
+ this.log.debug(`Getting process name for webview '${webview}'`);
454
+ const pkg = await this.adb.getNameByPid(pid);
455
+ this.log.debug(`Got process name: '${pkg}'`);
456
+ return pkg;
457
+ }
458
+ /**
459
+ * This function gets a list of android system processes and returns ones
460
+ * that look like webviews
461
+ * See https://cs.chromium.org/chromium/src/chrome/browser/devtools/device/android_device_info_query.cc
462
+ * for more details
463
+ *
464
+ * @this {import('../../driver').AndroidDriver}
465
+ * @returns {Promise<string[]>} a list of matching webview socket names (including the leading '@')
466
+ */
467
+ async function getPotentialWebviewProcs() {
468
+ const out = await this.adb.shell(['cat', '/proc/net/unix']);
469
+ /** @type {string[]} */
470
+ const names = [];
471
+ /** @type {string[]} */
472
+ const allMatches = [];
473
+ for (const line of out.split('\n')) {
474
+ // Num RefCount Protocol Flags Type St Inode Path
475
+ const [, , , flags, , st, , sockPath] = line.trim().split(/\s+/);
476
+ if (!sockPath) {
477
+ continue;
478
+ }
479
+ if (sockPath.startsWith('@')) {
480
+ allMatches.push(line.trim());
481
+ }
482
+ if (flags !== '00010000' || st !== '01') {
483
+ continue;
484
+ }
485
+ if (!exports.DEVTOOLS_SOCKET_PATTERN.test(sockPath)) {
486
+ continue;
487
+ }
488
+ names.push(sockPath);
489
+ }
490
+ if (lodash_1.default.isEmpty(names)) {
491
+ this.log.debug('Found no active devtools sockets');
492
+ if (!lodash_1.default.isEmpty(allMatches)) {
493
+ this.log.debug(`Other sockets are: ${JSON.stringify(allMatches, null, 2)}`);
494
+ }
495
+ }
496
+ else {
497
+ this.log.debug(`Parsed ${names.length} active devtools ${support_1.util.pluralize('socket', names.length, false)}: ` +
498
+ JSON.stringify(names));
499
+ }
500
+ // sometimes the webview process shows up multiple times per app
501
+ return lodash_1.default.uniq(names);
502
+ }
503
+ /**
504
+ * This function retrieves a list of system processes that look like webviews,
505
+ * and returns them along with the webview context name appropriate for it.
506
+ * If we pass in a deviceSocket, we only attempt to find webviews which match
507
+ * that socket name (this is for apps which embed Chromium, which isn't the
508
+ * same as chrome-backed webviews).
509
+ *
510
+ * @this {import('../../driver').AndroidDriver}
511
+ * @param {string?} [deviceSocket=null] - the explictly-named device socket to use
512
+ * @returns {Promise<import('../types').WebviewProc[]>}
513
+ */
514
+ async function webviewsFromProcs(deviceSocket = null) {
515
+ const socketNames = await getPotentialWebviewProcs.bind(this)();
516
+ /** @type {{proc: string; webview: string}[]} */
517
+ const webviews = [];
518
+ for (const socketName of socketNames) {
519
+ if (deviceSocket === CHROMIUM_DEVTOOLS_SOCKET && socketName === `@${deviceSocket}`) {
520
+ webviews.push({
521
+ proc: socketName,
522
+ webview: exports.CHROMIUM_WIN,
523
+ });
524
+ continue;
525
+ }
526
+ const socketNameMatch = exports.DEVTOOLS_SOCKET_PATTERN.exec(socketName);
527
+ if (!socketNameMatch) {
528
+ continue;
529
+ }
530
+ const matchedSocketName = socketNameMatch[2];
531
+ const crosswalkMatch = CROSSWALK_SOCKET_PATTERN.exec(socketName);
532
+ if (!matchedSocketName && !crosswalkMatch) {
533
+ continue;
534
+ }
535
+ if ((deviceSocket && socketName === `@${deviceSocket}`) || !deviceSocket) {
536
+ webviews.push({
537
+ proc: socketName,
538
+ webview: matchedSocketName
539
+ ? `${exports.WEBVIEW_BASE}${matchedSocketName}`
540
+ : // @ts-expect-error: XXX crosswalkMatch can absolutely be null
541
+ `${exports.WEBVIEW_BASE}${crosswalkMatch[1]}`,
542
+ });
543
+ }
544
+ }
545
+ return webviews;
546
+ }
547
+ /**
548
+ * @this {import('../../driver').AndroidDriver}
549
+ * @param {import('../types').PortSpec} [portSpec]
550
+ * @returns {Promise<number>}
551
+ */
552
+ async function getChromedriverPort(portSpec) {
553
+ // if the user didn't give us any specific information about chromedriver
554
+ // port ranges, just find any free port
555
+ if (!portSpec) {
556
+ const port = await getFreePort();
557
+ this.log.debug(`A port was not given, using random free port: ${port}`);
558
+ return port;
559
+ }
560
+ // otherwise find the free port based on a list or range provided by the user
561
+ this.log.debug(`Finding a free port for chromedriver using spec ${JSON.stringify(portSpec)}`);
562
+ let foundPort = null;
563
+ for (const potentialPort of portSpec) {
564
+ /** @type {number} */
565
+ let port;
566
+ /** @type {number} */
567
+ let stopPort;
568
+ if (Array.isArray(potentialPort)) {
569
+ [port, stopPort] = potentialPort.map((p) => parseInt(String(p), 10));
570
+ }
571
+ else {
572
+ port = parseInt(String(potentialPort), 10); // ensure we have a number and not a string
573
+ stopPort = port;
574
+ }
575
+ this.log.debug(`Checking port range ${port}:${stopPort}`);
576
+ try {
577
+ foundPort = await (0, portscanner_1.findAPortNotInUse)(port, stopPort);
578
+ break;
579
+ }
580
+ catch (e) {
581
+ this.log.debug(`Nothing in port range ${port}:${stopPort} was available`);
582
+ }
583
+ }
584
+ if (foundPort === null) {
585
+ throw new Error(`Could not find a free port for chromedriver using ` +
586
+ `chromedriverPorts spec ${JSON.stringify(portSpec)}`);
587
+ }
588
+ this.log.debug(`Using free port ${foundPort} for chromedriver`);
589
+ return foundPort;
590
+ }
591
+ /**
592
+ * @this {import('../../driver').AndroidDriver}
593
+ * @returns {boolean}
594
+ */
595
+ function isChromedriverAutodownloadEnabled() {
596
+ if (this.isFeatureEnabled(CHROMEDRIVER_AUTODOWNLOAD_FEATURE)) {
597
+ return true;
598
+ }
599
+ this.log.debug(`Automated Chromedriver download is disabled. ` +
600
+ `Use '${CHROMEDRIVER_AUTODOWNLOAD_FEATURE}' server feature to enable it`);
601
+ return false;
602
+ }
603
+ /**
604
+ * @this {import('../../driver').AndroidDriver}
605
+ * @param {import('../../driver').AndroidDriverOpts} opts
606
+ * @param {string} curDeviceId
607
+ * @param {string} [context]
608
+ * @returns {Promise<Chromedriver>}
609
+ */
610
+ async function setupNewChromedriver(opts, curDeviceId, context) {
611
+ // @ts-ignore TODO: Remove the legacy
612
+ if (opts.chromeDriverPort) {
613
+ this.log.warn(`The 'chromeDriverPort' capability is deprecated. Please use 'chromedriverPort' instead`);
614
+ // @ts-ignore TODO: Remove the legacy
615
+ opts.chromedriverPort = opts.chromeDriverPort;
616
+ }
617
+ if (opts.chromedriverPort) {
618
+ this.log.debug(`Using user-specified port ${opts.chromedriverPort} for chromedriver`);
619
+ }
620
+ else {
621
+ // if a single port wasn't given, we'll look for a free one
622
+ opts.chromedriverPort = await getChromedriverPort.bind(this)(opts.chromedriverPorts);
623
+ }
624
+ const details = context ? (0, cache_1.getWebviewDetails)(this.adb, context) : undefined;
625
+ if (!lodash_1.default.isEmpty(details)) {
626
+ this.log.debug('Passing web view details to the Chromedriver constructor: ' +
627
+ JSON.stringify(details, null, 2));
628
+ }
629
+ const chromedriver = new appium_chromedriver_1.default({
630
+ port: String(opts.chromedriverPort),
631
+ executable: opts.chromedriverExecutable,
632
+ // eslint-disable-next-line object-shorthand
633
+ adb: /** @type {any} */ (this.adb),
634
+ cmdArgs: /** @type {string[]} */ (opts.chromedriverArgs),
635
+ verbose: !!opts.showChromedriverLog,
636
+ executableDir: opts.chromedriverExecutableDir,
637
+ mappingPath: opts.chromedriverChromeMappingFile,
638
+ // @ts-ignore this property exists
639
+ bundleId: opts.chromeBundleId,
640
+ useSystemExecutable: opts.chromedriverUseSystemExecutable,
641
+ disableBuildCheck: opts.chromedriverDisableBuildCheck,
642
+ // @ts-ignore this is ok
643
+ details,
644
+ isAutodownloadEnabled: isChromedriverAutodownloadEnabled.bind(this)(),
645
+ });
646
+ // make sure there are chromeOptions
647
+ opts.chromeOptions = opts.chromeOptions || {};
648
+ // try out any prefixed chromeOptions,
649
+ // and strip the prefix
650
+ for (const opt of lodash_1.default.keys(opts)) {
651
+ if (opt.endsWith(':chromeOptions')) {
652
+ this?.log?.warn(`Merging '${opt}' into 'chromeOptions'. This may cause unexpected behavior`);
653
+ lodash_1.default.merge(opts.chromeOptions, opts[opt]);
654
+ }
655
+ }
656
+ const caps = /** @type {any} */ (createChromedriverCaps.bind(this)(opts, curDeviceId, details));
657
+ this.log.debug(`Before starting chromedriver, androidPackage is '${caps.chromeOptions.androidPackage}'`);
658
+ await chromedriver.start(caps);
659
+ return chromedriver;
660
+ }
661
+ exports.setupNewChromedriver = setupNewChromedriver;
662
+ /**
663
+ * @this {import('../../driver').AndroidDriver}
664
+ * @template {Chromedriver} T
665
+ * @param {T} chromedriver
666
+ * @returns {Promise<T>}
667
+ */
668
+ async function setupExistingChromedriver(chromedriver) {
669
+ // check the status by sending a simple window-based command to ChromeDriver
670
+ // if there is an error, we want to recreate the ChromeDriver session
671
+ if (!(await chromedriver.hasWorkingWebview())) {
672
+ this.log.debug('ChromeDriver is not associated with a window. Re-initializing the session.');
673
+ await chromedriver.restart();
674
+ }
675
+ return chromedriver;
676
+ }
677
+ exports.setupExistingChromedriver = setupExistingChromedriver;
678
+ /**
679
+ * @this {import('../../driver').AndroidDriver}
680
+ * @returns {boolean}
681
+ */
682
+ function shouldDismissChromeWelcome() {
683
+ return (!!this.opts.chromeOptions &&
684
+ lodash_1.default.isArray(this.opts.chromeOptions.args) &&
685
+ this.opts.chromeOptions.args.includes('--no-first-run'));
686
+ }
687
+ exports.shouldDismissChromeWelcome = shouldDismissChromeWelcome;
688
+ /**
689
+ * @this {import('../../driver').AndroidDriver}
690
+ * @returns {Promise<void>}
691
+ */
692
+ async function dismissChromeWelcome() {
693
+ this.log.info('Trying to dismiss Chrome welcome');
694
+ let activity = await this.getCurrentActivity();
695
+ if (activity !== 'org.chromium.chrome.browser.firstrun.FirstRunActivity') {
696
+ this.log.info('Chrome welcome dialog never showed up! Continuing');
697
+ return;
698
+ }
699
+ let el = await this.findElOrEls('id', 'com.android.chrome:id/terms_accept', false);
700
+ await this.click(/** @type {string} */ (el.ELEMENT));
701
+ try {
702
+ let el = await this.findElOrEls('id', 'com.android.chrome:id/negative_button', false);
703
+ await this.click(/** @type {string} */ (el.ELEMENT));
704
+ }
705
+ catch (e) {
706
+ // DO NOTHING, THIS DEVICE DIDNT LAUNCH THE SIGNIN DIALOG
707
+ // IT MUST BE A NON GMS DEVICE
708
+ this.log.warn(`This device did not show Chrome SignIn dialog, ${ /** @type {Error} */(e).message}`);
709
+ }
710
+ }
711
+ exports.dismissChromeWelcome = dismissChromeWelcome;
712
+ /**
713
+ * @typedef {import('appium-adb').ADB} ADB
714
+ */
715
+ //# sourceMappingURL=helpers.js.map