UNPKG

appium-chromium-driver

Version:

Appium driver for Chromium-based browsers that work with Chromedriver

52 lines 2.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveDriverVersionForBrowser = resolveDriverVersionForBrowser; exports.fetchDriverArchive = fetchDriverArchive; const support_1 = require("appium/support"); const platform_1 = require("./platform"); const version_1 = require("./version"); const DRIVER_STORAGE_BASE_URL = 'https://msedgedriver.microsoft.com'; const STORAGE_REQUEST_TIMEOUT_MS = 10_000; const UTF16LE_BOM = Buffer.from([0xff, 0xfe]); /** * Resolve the compatible MSEdgeDriver version for a given browser version * via the official Microsoft Edge Driver service. * @param browserVersion The version of the browser. * @returns The version of the MSEdgeDriver. */ async function resolveDriverVersionForBrowser(browserVersion) { const releaseUrl = getLatestReleaseUrl(browserVersion); const response = await fetch(releaseUrl, { method: 'GET', signal: AbortSignal.timeout(STORAGE_REQUEST_TIMEOUT_MS), }); if (!response.ok) { throw new Error(`Cannot retrieve MSEdgeDriver version for Edge '${browserVersion}' from '${releaseUrl}' ` + `(status ${response.status})`); } // The response body is expected to be a small and simple text with the version string, e.g., "147.0.3179.98". const text = decodeVersionResponse(Buffer.from(await response.arrayBuffer())); return version_1.Version.from(text); } /** * Fetch the MSEdgeDriver archive for the given driver version. * @param driverVersion The MSEdgeDriver version to download. * @param archivePath The local path where the archive should be written. */ async function fetchDriverArchive(driverVersion, archivePath) { await support_1.net.downloadFile(getDriverDownloadUrl(driverVersion), archivePath); } function getLatestReleaseUrl(browserVersion) { const { releaseChannel } = (0, platform_1.getPlatformConfig)(); return `${DRIVER_STORAGE_BASE_URL}/LATEST_RELEASE_${browserVersion.major}_${releaseChannel}`; } function getDriverDownloadUrl(driverVersion) { return `${DRIVER_STORAGE_BASE_URL}/${driverVersion}/${(0, platform_1.getPlatformConfig)().archiveName}`; } function decodeVersionResponse(payload) { if (payload.subarray(0, UTF16LE_BOM.length).equals(UTF16LE_BOM)) { return payload.subarray(UTF16LE_BOM.length).toString('utf16le').trim(); } return payload.toString('utf8').trim(); } //# sourceMappingURL=download.js.map