diff --git a/src/constants.ts b/src/constants.ts index b614e00b..e9737a8a 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,6 @@ import os from 'node:os' -export const MOZ_CENTRAL_CARGO_TOML = 'https://hg.mozilla.org/mozilla-central/raw-file/tip/testing/geckodriver/Cargo.toml' +export const GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest' export const BASE_CDN_URL = process.env.GECKODRIVER_CDNURL || process.env.npm_config_geckodriver_cdnurl || 'https://github.com/mozilla/geckodriver/releases/download' // e.g. https://github.com/mozilla/geckodriver/releases/download/v0.33.0/geckodriver-v0.33.0-macos-aarch64.tar.gz export const GECKODRIVER_DOWNLOAD_PATH = `${BASE_CDN_URL}/v%s/geckodriver-v%s-%s%s%s` diff --git a/src/install.ts b/src/install.ts index d299e8bd..00a3f7f6 100644 --- a/src/install.ts +++ b/src/install.ts @@ -14,7 +14,7 @@ import { HttpsProxyAgent } from 'https-proxy-agent' import { HttpProxyAgent } from 'http-proxy-agent' import unzipper, { type Entry } from 'unzipper' -import { BINARY_FILE, MOZ_CENTRAL_CARGO_TOML } from './constants.js' +import { BINARY_FILE, GECKODRIVER_RELEASES } from './constants.js' import { hasAccess, getDownloadUrl, retryFetch } from './utils.js' const log = logger('geckodriver') @@ -40,13 +40,12 @@ export async function download ( * get latest version of Geckodriver */ if (!geckodriverVersion) { - const res = await retryFetch(MOZ_CENTRAL_CARGO_TOML, fetchOpts) - const toml = await res.text() - const version = toml.split('\n').find((l) => l.startsWith('version = ')) - if (!version) { - throw new Error(`Couldn't find version property in Cargo.toml file: ${toml}`) + const res = await retryFetch(GECKODRIVER_RELEASES, fetchOpts) + const releases = await res.json() as { name: string } + geckodriverVersion = releases.name + if (!geckodriverVersion) { + throw new Error(`Couldn't find version name in releases: ${JSON.stringify(releases)}`) } - geckodriverVersion = version.split(' = ').pop().slice(1, -1) log.info(`Detected Geckodriver v${geckodriverVersion} to be latest`) }