-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
62 changed files
with
4,151 additions
and
845 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { resolveBuildId, canDownload, install as puppeteerInstall } from "@puppeteer/browsers"; | ||
import { MIN_CHROME_FOR_TESTING_VERSION } from "../constants"; | ||
import { | ||
browserInstallerDebug, | ||
getBrowserPlatform, | ||
getBrowsersDir, | ||
getMilestone, | ||
Browser, | ||
type DownloadProgressCallback, | ||
} from "../utils"; | ||
import { getBinaryPath, getMatchedBrowserVersion, installBinary } from "../registry"; | ||
import { normalizeChromeVersion } from "../utils"; | ||
|
||
export const installChrome = async (version: string, { force = false } = {}): Promise<string> => { | ||
const milestone = getMilestone(version); | ||
|
||
if (Number(milestone) < MIN_CHROME_FOR_TESTING_VERSION) { | ||
browserInstallerDebug(`couldn't install chrome@${version}, installing chromium instead`); | ||
|
||
const { installChromium } = await import("../chromium"); | ||
|
||
return installChromium(version, { force }); | ||
} | ||
|
||
const platform = getBrowserPlatform(); | ||
const existingLocallyBrowserVersion = getMatchedBrowserVersion(Browser.CHROME, platform, version); | ||
|
||
if (existingLocallyBrowserVersion && !force) { | ||
browserInstallerDebug(`A locally installed chrome@${version} browser was found. Skipping the installation`); | ||
|
||
return getBinaryPath(Browser.CHROME, platform, existingLocallyBrowserVersion); | ||
} | ||
|
||
const normalizedVersion = normalizeChromeVersion(version); | ||
const buildId = await resolveBuildId(Browser.CHROME, platform, normalizedVersion); | ||
|
||
const cacheDir = getBrowsersDir(); | ||
const canBeInstalled = await canDownload({ browser: Browser.CHROME, platform, buildId, cacheDir }); | ||
|
||
if (!canBeInstalled) { | ||
throw new Error( | ||
[ | ||
`chrome@${version} can't be installed.`, | ||
`Probably the version '${version}' is invalid, please try another version.`, | ||
"Version examples: '120', '120.0'", | ||
].join("\n"), | ||
); | ||
} | ||
|
||
const installFn = (downloadProgressCallback: DownloadProgressCallback): Promise<string> => | ||
puppeteerInstall({ | ||
platform, | ||
buildId, | ||
cacheDir, | ||
downloadProgressCallback, | ||
browser: Browser.CHROME, | ||
unpack: true, | ||
}).then(result => result.executablePath); | ||
|
||
return installBinary(Browser.CHROME, platform, buildId, installFn); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { resolveBuildId, install as puppeteerInstall, canDownload } from "@puppeteer/browsers"; | ||
import { MIN_CHROMEDRIVER_FOR_TESTING_VERSION } from "../constants"; | ||
import { | ||
browserInstallerDebug, | ||
getBrowserPlatform, | ||
getChromeDriverDir, | ||
getMilestone, | ||
Driver, | ||
type DownloadProgressCallback, | ||
} from "../utils"; | ||
import { getBinaryPath, getMatchedDriverVersion, installBinary } from "../registry"; | ||
|
||
export const installChromeDriver = async (chromeVersion: string, { force = false } = {}): Promise<string> => { | ||
const platform = getBrowserPlatform(); | ||
const existingLocallyDriverVersion = getMatchedDriverVersion(Driver.CHROMEDRIVER, platform, chromeVersion); | ||
|
||
if (existingLocallyDriverVersion && !force) { | ||
browserInstallerDebug( | ||
`A locally installed chromedriver for chrome@${chromeVersion} was found. Skipping the installation`, | ||
); | ||
|
||
return getBinaryPath(Driver.CHROMEDRIVER, platform, existingLocallyDriverVersion); | ||
} | ||
|
||
const milestone = getMilestone(chromeVersion); | ||
|
||
if (Number(milestone) < MIN_CHROMEDRIVER_FOR_TESTING_VERSION) { | ||
browserInstallerDebug( | ||
`installing chromedriver for chrome@${chromeVersion} from chromedriver.storage.googleapis.com manually`, | ||
); | ||
|
||
const { installChromeDriverManually } = await import("../chromium"); | ||
|
||
return installChromeDriverManually(milestone); | ||
} | ||
|
||
const buildId = await resolveBuildId(Driver.CHROMEDRIVER, platform, milestone); | ||
|
||
const cacheDir = getChromeDriverDir(); | ||
const canBeInstalled = await canDownload({ browser: Driver.CHROMEDRIVER, platform, buildId, cacheDir }); | ||
|
||
if (!canBeInstalled) { | ||
throw new Error( | ||
[ | ||
`chromedriver@${buildId} can't be installed.`, | ||
`Probably the major browser version '${milestone}' is invalid`, | ||
"Correct chrome version examples: '123', '124'", | ||
].join("\n"), | ||
); | ||
} | ||
|
||
const installFn = (downloadProgressCallback: DownloadProgressCallback): Promise<string> => | ||
puppeteerInstall({ | ||
platform, | ||
buildId, | ||
cacheDir: getChromeDriverDir(), | ||
browser: Driver.CHROMEDRIVER, | ||
unpack: true, | ||
downloadProgressCallback, | ||
}).then(result => result.executablePath); | ||
|
||
return installBinary(Driver.CHROMEDRIVER, platform, buildId, installFn); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { spawn, type ChildProcess } from "child_process"; | ||
import getPort from "get-port"; | ||
import waitPort from "wait-port"; | ||
import { pipeLogsWithPrefix } from "../../dev-server/utils"; | ||
import { DRIVER_WAIT_TIMEOUT } from "../constants"; | ||
import { getMilestone } from "../utils"; | ||
import { installChrome } from "./browser"; | ||
import { installChromeDriver } from "./driver"; | ||
|
||
export { installChrome, installChromeDriver }; | ||
|
||
export const runChromeDriver = async ( | ||
chromeVersion: string, | ||
{ debug = false } = {}, | ||
): Promise<{ gridUrl: string; process: ChildProcess; port: number }> => { | ||
const [chromeDriverPath] = await Promise.all([installChromeDriver(chromeVersion), installChrome(chromeVersion)]); | ||
|
||
const milestone = getMilestone(chromeVersion); | ||
const randomPort = await getPort(); | ||
|
||
const chromeDriver = spawn(chromeDriverPath, [`--port=${randomPort}`, debug ? `--verbose` : "--silent"], { | ||
windowsHide: true, | ||
detached: false, | ||
}); | ||
|
||
if (debug) { | ||
pipeLogsWithPrefix(chromeDriver, `[chromedriver@${milestone}] `); | ||
} | ||
|
||
const gridUrl = `http://127.0.0.1:${randomPort}`; | ||
|
||
process.once("exit", () => chromeDriver.kill()); | ||
|
||
await waitPort({ port: randomPort, output: "silent", timeout: DRIVER_WAIT_TIMEOUT }); | ||
|
||
return { gridUrl, process: chromeDriver, port: randomPort }; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { install as puppeteerInstall, canDownload } from "@puppeteer/browsers"; | ||
import { installBinary, getBinaryPath, getMatchedBrowserVersion } from "../registry"; | ||
import { getMilestone, browserInstallerDebug, getBrowsersDir, Browser, type DownloadProgressCallback } from "../utils"; | ||
import { getChromiumBuildId } from "./utils"; | ||
import { getChromePlatform } from "../utils"; | ||
import { MIN_CHROMIUM_VERSION } from "../constants"; | ||
|
||
export const installChromium = async (version: string, { force = false } = {}): Promise<string> => { | ||
const milestone = getMilestone(version); | ||
|
||
if (Number(milestone) < MIN_CHROMIUM_VERSION) { | ||
throw new Error( | ||
[ | ||
`chrome@${version} can't be installed.`, | ||
`Automatic browser downloader is not available for chrome versions < ${MIN_CHROMIUM_VERSION}`, | ||
].join("\n"), | ||
); | ||
} | ||
|
||
const platform = getChromePlatform(version); | ||
const existingLocallyBrowserVersion = getMatchedBrowserVersion(Browser.CHROMIUM, platform, version); | ||
|
||
if (existingLocallyBrowserVersion && !force) { | ||
browserInstallerDebug(`A locally installed chromium@${version} browser was found. Skipping the installation`); | ||
|
||
return getBinaryPath(Browser.CHROMIUM, platform, existingLocallyBrowserVersion); | ||
} | ||
|
||
const buildId = await getChromiumBuildId(platform, milestone); | ||
const cacheDir = getBrowsersDir(); | ||
const canBeInstalled = await canDownload({ browser: Browser.CHROMIUM, platform, buildId, cacheDir }); | ||
|
||
if (!canBeInstalled) { | ||
throw new Error( | ||
[ | ||
`chrome@${version} can't be installed.`, | ||
`Probably the version '${version}' is invalid, please try another version.`, | ||
"Version examples: '93', '93.0'", | ||
].join("\n"), | ||
); | ||
} | ||
|
||
browserInstallerDebug(`installing chromium@${buildId} (${milestone}) for ${platform}`); | ||
|
||
const installFn = (downloadProgressCallback: DownloadProgressCallback): Promise<string> => | ||
puppeteerInstall({ | ||
platform, | ||
buildId, | ||
cacheDir, | ||
downloadProgressCallback, | ||
browser: Browser.CHROMIUM, | ||
unpack: true, | ||
}).then(result => result.executablePath); | ||
|
||
return installBinary(Browser.CHROMIUM, platform, milestone, installFn); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import fs from "fs-extra"; | ||
import path from "path"; | ||
import { noop } from "lodash"; | ||
import { CHROMEDRIVER_STORAGE_API, MIN_CHROMIUM_VERSION } from "../constants"; | ||
import { installBinary } from "../registry"; | ||
import { | ||
downloadFile, | ||
getChromiumDriverDir, | ||
retryFetch, | ||
unzipFile, | ||
normalizeChromeVersion, | ||
Driver, | ||
getBrowserPlatform, | ||
} from "../utils"; | ||
import { getChromeDriverArchiveTmpPath, getChromeDriverArchiveUrl } from "./utils"; | ||
|
||
const getChromeDriverVersionByChromiumVersion = async (chromiumVersion: string | number): Promise<string> => { | ||
const suffix = typeof chromiumVersion === "number" ? chromiumVersion : normalizeChromeVersion(chromiumVersion); | ||
|
||
const result = await retryFetch(`${CHROMEDRIVER_STORAGE_API}/LATEST_RELEASE_${suffix}`).then(res => res.text()); | ||
|
||
return result; | ||
}; | ||
|
||
export const installChromeDriverManually = async (milestone: string): Promise<string> => { | ||
const platform = getBrowserPlatform(); | ||
|
||
if (Number(milestone) < MIN_CHROMIUM_VERSION) { | ||
throw new Error( | ||
[ | ||
`chromedriver@${milestone} can't be installed.`, | ||
`Automatic driver downloader is not available for chrome versions < ${MIN_CHROMIUM_VERSION}`, | ||
].join("\n"), | ||
); | ||
} | ||
|
||
const driverVersion = await getChromeDriverVersionByChromiumVersion(milestone); | ||
|
||
const installFn = async (): Promise<string> => { | ||
const archiveUrl = getChromeDriverArchiveUrl(driverVersion); | ||
const archivePath = getChromeDriverArchiveTmpPath(driverVersion); | ||
const chromeDriverDirPath = getChromiumDriverDir(driverVersion); | ||
const chromeDriverPath = path.join(chromeDriverDirPath, "chromedriver"); | ||
|
||
await downloadFile(archiveUrl, archivePath); | ||
await unzipFile(archivePath, chromeDriverDirPath); | ||
|
||
fs.remove(archivePath).then(noop, noop); | ||
|
||
return chromeDriverPath; | ||
}; | ||
|
||
return installBinary(Driver.CHROMEDRIVER, platform, driverVersion, installFn); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { installChromium } from "./browser"; | ||
export { installChromeDriverManually } from "./driver"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export default { | ||
73: 625983, | ||
74: 638903, | ||
75: 652459, | ||
76: 665032, | ||
77: 681154, | ||
78: 694594, | ||
79: 707231, | ||
80: 722374, | ||
81: 737198, | ||
82: 750023, | ||
83: 756143, | ||
84: 769125, | ||
85: 782822, | ||
86: 800433, | ||
87: 813060, | ||
88: 827143, | ||
89: 843934, | ||
90: 858016, | ||
91: 870827, | ||
92: 885357, | ||
93: 902296, | ||
94: 911605, | ||
95: 920070, | ||
96: 929514, | ||
97: 938637, | ||
98: 950416, | ||
99: 961779, | ||
100: 972803, | ||
101: 982577, | ||
102: 992824, | ||
103: 1002974, | ||
104: 1012822, | ||
105: 1027072, | ||
106: 1036920, | ||
107: 1047812, | ||
108: 1059082, | ||
109: 1070158, | ||
110: 1084167, | ||
111: 1097778, | ||
112: 1107206, | ||
} as Record<number, number>; |
Oops, something went wrong.