summaryrefslogtreecommitdiffstats
path: root/remote/test/puppeteer/packages/browsers/src/install.ts
diff options
context:
space:
mode:
Diffstat (limited to 'remote/test/puppeteer/packages/browsers/src/install.ts')
-rw-r--r--remote/test/puppeteer/packages/browsers/src/install.ts118
1 files changed, 100 insertions, 18 deletions
diff --git a/remote/test/puppeteer/packages/browsers/src/install.ts b/remote/test/puppeteer/packages/browsers/src/install.ts
index 375c75babc..e78b2c3461 100644
--- a/remote/test/puppeteer/packages/browsers/src/install.ts
+++ b/remote/test/puppeteer/packages/browsers/src/install.ts
@@ -11,15 +11,15 @@ import os from 'os';
import path from 'path';
import {
- type Browser,
- type BrowserPlatform,
+ Browser,
+ BrowserPlatform,
downloadUrls,
} from './browser-data/browser-data.js';
import {Cache, InstalledBrowser} from './Cache.js';
import {debug} from './debug.js';
import {detectBrowserPlatform} from './detectPlatform.js';
import {unpackArchive} from './fileUtil.js';
-import {downloadFile, headHttpRequest} from './httpUtil.js';
+import {downloadFile, getJSON, headHttpRequest} from './httpUtil.js';
const debugInstall = debug('puppeteer:browsers:install');
@@ -63,6 +63,13 @@ export interface InstallOptions {
*/
buildId: string;
/**
+ * An alias for the provided `buildId`. It will be used to maintain local
+ * metadata to support aliases in the `launch` command.
+ *
+ * @example 'canary'
+ */
+ buildIdAlias?: string;
+ /**
* Provides information about the progress of the download.
*/
downloadProgressCallback?: (
@@ -74,7 +81,7 @@ export interface InstallOptions {
*
* @defaultValue Either
*
- * - https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing or
+ * - https://storage.googleapis.com/chrome-for-testing-public or
* - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
*
*/
@@ -115,6 +122,68 @@ export async function install(
options.buildId,
options.baseUrl
);
+ try {
+ return await installUrl(url, options);
+ } catch (err) {
+ debugInstall(`Error downloading from ${url}.`);
+ switch (options.browser) {
+ case Browser.CHROME:
+ case Browser.CHROMEDRIVER:
+ case Browser.CHROMEHEADLESSSHELL: {
+ debugInstall(
+ `Trying to find download URL via https://googlechromelabs.github.io/chrome-for-testing.`
+ );
+ interface Version {
+ downloads: Record<string, Array<{platform: string; url: string}>>;
+ }
+ const version = (await getJSON(
+ new URL(
+ `https://googlechromelabs.github.io/chrome-for-testing/${options.buildId}.json`
+ )
+ )) as Version;
+ let platform = '';
+ switch (options.platform) {
+ case BrowserPlatform.LINUX:
+ platform = 'linux64';
+ break;
+ case BrowserPlatform.MAC_ARM:
+ platform = 'mac-arm64';
+ break;
+ case BrowserPlatform.MAC:
+ platform = 'mac-x64';
+ break;
+ case BrowserPlatform.WIN32:
+ platform = 'win32';
+ break;
+ case BrowserPlatform.WIN64:
+ platform = 'win64';
+ break;
+ }
+ const url = version.downloads[options.browser]?.find(link => {
+ return link['platform'] === platform;
+ })?.url;
+ if (url) {
+ debugInstall(`Falling back to downloading from ${url}.`);
+ return await installUrl(new URL(url), options);
+ }
+ throw err;
+ }
+ default:
+ throw err;
+ }
+ }
+}
+
+async function installUrl(
+ url: URL,
+ options: InstallOptions
+): Promise<InstalledBrowser | string> {
+ options.platform ??= detectBrowserPlatform();
+ if (!options.platform) {
+ throw new Error(
+ `Cannot download a binary for the provided platform: ${os.platform()} (${os.arch()})`
+ );
+ }
const fileName = url.toString().split('/').pop();
assert(fileName, `A malformed download URL was found: ${url}.`);
const cache = new Cache(options.cacheDir);
@@ -140,15 +209,22 @@ export async function install(
options.platform,
options.buildId
);
- if (existsSync(outputPath)) {
- return new InstalledBrowser(
- cache,
- options.browser,
- options.buildId,
- options.platform
- );
- }
+
try {
+ if (existsSync(outputPath)) {
+ const installedBrowser = new InstalledBrowser(
+ cache,
+ options.browser,
+ options.buildId,
+ options.platform
+ );
+ if (!existsSync(installedBrowser.executablePath)) {
+ throw new Error(
+ `The browser folder (${outputPath}) exists but the executable (${installedBrowser.executablePath}) is missing`
+ );
+ }
+ return installedBrowser;
+ }
debugInstall(`Downloading binary from ${url}`);
try {
debugTime('download');
@@ -164,17 +240,23 @@ export async function install(
} finally {
debugTimeEnd('extract');
}
+ const installedBrowser = new InstalledBrowser(
+ cache,
+ options.browser,
+ options.buildId,
+ options.platform
+ );
+ if (options.buildIdAlias) {
+ const metadata = installedBrowser.readMetadata();
+ metadata.aliases[options.buildIdAlias] = options.buildId;
+ installedBrowser.writeMetadata(metadata);
+ }
+ return installedBrowser;
} finally {
if (existsSync(archivePath)) {
await unlink(archivePath);
}
}
- return new InstalledBrowser(
- cache,
- options.browser,
- options.buildId,
- options.platform
- );
}
/**