UNPKG

appium-chromium-driver

Version:

Appium driver for Chromium-based browsers that work with Chromedriver

82 lines 3.12 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.getWindowsExecutableCandidates = getWindowsExecutableCandidates; exports.readBrowserVersion = readBrowserVersion; const node_path_1 = __importDefault(require("node:path")); const teen_process_1 = require("teen_process"); /** * Build Windows executable candidate paths from common installation base folders. * @param subdirs Relative installation subdirectories. * @param exe Executable file name. * @returns Absolute candidate executable paths. */ function getWindowsExecutableCandidates(subdirs, exe) { const bases = [ process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)'], process.env.LOCALAPPDATA, ]; return bases .filter((base) => Boolean(base)) .flatMap((base) => subdirs.map((sub) => node_path_1.default.join(base, sub, exe))); } /** * Read browser version from the given executable path or command. * @param binary Browser executable path or command. * @returns Browser version if detected, otherwise null. */ async function readBrowserVersion(binary) { return process.platform === 'win32' ? await readBrowserVersionWin(binary) : await readBrowserVersionUnix(binary); } /** * On Windows, retrieve the browser version via PowerShell's VersionInfo instead of --version, * because Chrome/Edge do not reliably write to stdout when spawned via exec. */ async function readBrowserVersionWin(binaryPath) { // Escape single quotes for PowerShell single-quoted strings const safePath = binaryPath.replace(/'/g, "''"); try { const { stdout } = await (0, teen_process_1.exec)('powershell', [ '-NoProfile', '-Command', [ `$target = '${safePath}'`, `if (-not [System.IO.Path]::IsPathRooted($target)) {`, ` $resolved = Get-Command $target -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty Source`, ` if ($resolved) { $target = $resolved }`, `}`, `if (Test-Path $target) { (Get-Item $target).VersionInfo.ProductVersion }`, ].join('; '), ]); const version = stdout.trim(); if (/^\d+\.\d+/.test(version)) { return version; } } catch { // binary not found or PowerShell failed; caller will try next candidate } return null; } /** * On Unix, retrieve the browser version by running the binary with `--version` and parsing stdout. */ async function readBrowserVersionUnix(binary) { try { const { stdout } = await (0, teen_process_1.exec)(binary, ['--version']); const match = /(\d+\.\d+\.\d+\.\d+)/.exec(stdout); if (match) { return match[1]; } } catch { // binary not found or failed; caller will try next candidate } return null; } //# sourceMappingURL=utils.js.map