UNPKG

appium-chromedriver

Version:
173 lines 7.09 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; }; })(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseKnownGoodVersionsWithDownloadsJson = parseKnownGoodVersionsWithDownloadsJson; exports.parseLatestKnownGoodVersionsJson = parseLatestKnownGoodVersionsJson; const node_path_1 = __importDefault(require("node:path")); const support_1 = require("@appium/support"); const semver = __importStar(require("semver")); const constants_1 = require("../constants"); const log = support_1.logger.getLogger('ChromedriverChromelabsStorageClient'); /** * Parses the output of the JSON API that retrieves Chromedriver versions * * See https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints for more details. * * @param jsonStr - The JSON string from the known-good-versions-with-downloads API * @returns A mapping of chromedriver entry keys to their details * @throws {Error} if the JSON cannot be parsed or has an unsupported format */ function parseKnownGoodVersionsWithDownloadsJson(jsonStr) { let json; try { json = JSON.parse(jsonStr); } catch (e) { throw new Error(`Storage JSON cannot be parsed. Original error: ${e instanceof Error ? e.message : String(e)}`, { cause: e }); } /** * Example output: * { * "timestamp":"2023-07-28T13:09:17.042Z", * "versions":[ * { * "version":"113.0.5672.0", * "revision":"1121455", * "downloads":{ * "chromedriver":[ * { * "platform":"linux64", * "url":"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/linux64/chrome-linux64.zip" * }, * { * "platform":"mac-arm64", * "url":"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-arm64/chrome-mac-arm64.zip" * }, * { * "platform":"mac-x64", * "url":"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/mac-x64/chrome-mac-x64.zip" * }, * { * "platform":"win32", * "url":"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win32/chrome-win32.zip" * }, * { * "platform":"win64", * "url":"https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/113.0.5672.0/win64/chrome-win64.zip" * } * ] * } * }, * { * "version":"113.0.5672.35", * ... */ const mapping = {}; if (!Array.isArray(json?.versions)) { log.debug(jsonStr); throw new Error('The format of the storage JSON is not supported'); } for (const { version, downloads } of json.versions) { if (!Array.isArray(downloads?.chromedriver)) { continue; } const versionObj = semver.parse(version, { loose: true }); if (!versionObj) { continue; } for (const downloadEntry of downloads.chromedriver) { if (!downloadEntry?.url || !downloadEntry?.platform) { continue; } const osNameMatch = /^[a-z]+/i.exec(downloadEntry.platform); if (!osNameMatch) { log.debug(`The entry '${downloadEntry.url}' does not contain valid platform name. Skipping it`); continue; } const key = `${node_path_1.default.basename(node_path_1.default.dirname(node_path_1.default.dirname(downloadEntry.url)))}/` + `${node_path_1.default.basename(downloadEntry.url)}`; mapping[key] = { url: downloadEntry.url, etag: null, version, minBrowserVersion: `${versionObj.major}`, os: { name: osNameMatch[0], arch: downloadEntry.platform.includes(constants_1.ARCH.X64) ? constants_1.ARCH.X64 : constants_1.ARCH.X86, cpu: downloadEntry.platform.includes(constants_1.CPU.ARM) ? constants_1.CPU.ARM : constants_1.CPU.INTEL, }, }; } } log.info(`The total count of entries in the mapping: ${Object.keys(mapping).length}`); return mapping; } /** * Parses the output of the JSON API that retrieves the most recent stable Chromedriver version * * See https://github.com/GoogleChromeLabs/chrome-for-testing#json-api-endpoints for more details. * * @param jsonStr - The JSON string from the last-known-good-versions API * @returns The most recent available chromedriver version string * @throws {Error} if the JSON cannot be parsed or has an unsupported format */ function parseLatestKnownGoodVersionsJson(jsonStr) { let json; try { json = JSON.parse(jsonStr); } catch (e) { throw new Error(`Storage JSON cannot be parsed. Original error: ${e instanceof Error ? e.message : String(e)}`, { cause: e }); } /** * Example output: * "timestamp":"2023-07-28T13:09:17.036Z", * "channels":{ * "Stable":{ * "channel":"Stable", * "version":"115.0.5790.102", * "revision":"1148114" * ... */ if (!json?.channels?.Stable?.version) { log.debug(jsonStr); throw new Error('The format of the storage JSON is not supported'); } return json.channels.Stable.version; } //# sourceMappingURL=chromelabs.js.map