diff --git a/src/constants.ts b/src/constants.ts index e9737a8a..accfde63 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,6 +1,6 @@ import os from 'node:os' -export const GECKODRIVER_RELEASES = 'https://api.github.com/repos/mozilla/geckodriver/releases/latest' +export const GECKODRIVER_CARGO_YAML = 'https://raw.githubusercontent.com/mozilla/geckodriver/release/Cargo.toml' 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 709aa2fc..f93718e9 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, GECKODRIVER_RELEASES } from './constants.js' +import { BINARY_FILE, GECKODRIVER_CARGO_YAML } from './constants.js' import { hasAccess, getDownloadUrl, retryFetch } from './utils.js' const log = logger('geckodriver') @@ -40,12 +40,13 @@ export async function download ( * get latest version of Geckodriver */ if (!geckodriverVersion) { - 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)}`) + const res = await retryFetch(GECKODRIVER_CARGO_YAML, 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: ${JSON.stringify(toml)}`) } + geckodriverVersion = version.split(' = ').pop().slice(1, -1) log.info(`Detected Geckodriver v${geckodriverVersion} to be latest`) }