UNPKG

appium-chromedriver

Version:
121 lines 4.75 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.getChromeVersionForAutodetection = getChromeVersionForAutodetection; const semver = __importStar(require("semver")); const utils_1 = require("../utils"); const CHROME_BUNDLE_ID = 'com.android.chrome'; const WEBVIEW_SHELL_BUNDLE_ID = 'org.chromium.webview_shell'; const WEBVIEW_BUNDLE_IDS = ['com.google.android.webview', 'com.android.webview']; const VERSION_PATTERN = /([\d.]+)/; /** * Detects Chrome/WebView version to drive Chromedriver compatibility matching. */ async function getChromeVersionForAutodetection() { // Prefer already-collected CDP details when available. const fromDetails = tryCoerceVersionFromCdpDetails(this); if (fromDetails) { return fromDetails; } // In WebView shell mode, probe known system webview packages first. if (this.bundleId === WEBVIEW_SHELL_BUNDLE_ID) { return await resolveChromeVersionForWebviewShell(this); } // Android 7-9 webviews are backed by main Chrome package. await remapLegacyWebviewBundleId(this); // Default to generic Chrome and fall back to known webview providers. let chromeVersion = await resolveChromeVersionByProbingWebviews(this); // If no webview package matched, check the selected/default bundle id directly. if (!chromeVersion && this.adb) { const bundleId = this.bundleId ?? CHROME_BUNDLE_ID; chromeVersion = (await (0, utils_1.getChromeVersion)(this.adb, bundleId)) ?? null; } return chromeVersion ? semver.coerce(chromeVersion) : null; } function tryCoerceVersionFromCdpDetails(ctx) { if (ctx.details?.info) { ctx.log.debug(`Browser version in the supplied details: ${ctx.details?.info?.Browser}`); } const versionMatch = VERSION_PATTERN.exec(ctx.details?.info?.Browser ?? ''); if (!versionMatch) { return null; } return semver.coerce(versionMatch[1]); } async function resolveChromeVersionForWebviewShell(ctx) { if (!ctx.adb) { return null; } for (const bundleId of WEBVIEW_BUNDLE_IDS) { const chromeVersion = await (0, utils_1.getChromeVersion)(ctx.adb, bundleId); if (chromeVersion) { ctx.bundleId = bundleId; return semver.coerce(chromeVersion); } } return null; } async function remapLegacyWebviewBundleId(ctx) { if (!ctx.adb) { return; } const apiLevel = await ctx.adb.getApiLevel(); const isLegacyWebviewBundle = [WEBVIEW_SHELL_BUNDLE_ID, ...WEBVIEW_BUNDLE_IDS].includes(ctx.bundleId ?? ''); if (apiLevel >= 24 && apiLevel <= 28 && isLegacyWebviewBundle) { ctx.bundleId = CHROME_BUNDLE_ID; } } /** * When no bundle id is set, default to Chrome and probe known WebView providers. * Returns a version string if a WebView package reports one; otherwise leaves bundleId as Chrome. */ async function resolveChromeVersionByProbingWebviews(ctx) { if (ctx.bundleId) { return null; } ctx.bundleId = CHROME_BUNDLE_ID; if (!ctx.adb) { return null; } for (const bundleId of WEBVIEW_BUNDLE_IDS) { const chromeVersion = await (0, utils_1.getChromeVersion)(ctx.adb, bundleId); if (chromeVersion) { ctx.bundleId = bundleId; return chromeVersion; } } return null; } //# sourceMappingURL=version.js.map