mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
chore: allow downloading the latest Chrome version (#9719)
This commit is contained in:
parent
84845e4901
commit
e3d8524738
@ -20,6 +20,7 @@ import {hideBin} from 'yargs/helpers';
|
||||
|
||||
import {resolveRevision} from './browsers/browsers.js';
|
||||
import {Browser, BrowserPlatform} from './browsers/types.js';
|
||||
import {detectBrowserPlatform} from './detectPlatform.js';
|
||||
import {fetch} from './fetch.js';
|
||||
import {computeExecutablePath, launch} from './launcher.js';
|
||||
|
||||
@ -68,8 +69,13 @@ export class CLI {
|
||||
},
|
||||
async argv => {
|
||||
const args = argv as unknown as InstallArgs;
|
||||
args.platform ??= detectBrowserPlatform();
|
||||
if (!args.platform) {
|
||||
throw new Error(`Could not resolve the current platform`);
|
||||
}
|
||||
args.browser.revision = await resolveRevision(
|
||||
args.browser.name,
|
||||
args.platform,
|
||||
args.browser.revision
|
||||
);
|
||||
await fetch({
|
||||
|
@ -32,6 +32,7 @@ export {Browser, BrowserPlatform};
|
||||
|
||||
export async function resolveRevision(
|
||||
browser: Browser,
|
||||
platform: BrowserPlatform,
|
||||
tag: string
|
||||
): Promise<string> {
|
||||
switch (browser) {
|
||||
@ -40,6 +41,11 @@ export async function resolveRevision(
|
||||
case BrowserTag.LATEST:
|
||||
return await firefox.resolveRevision('FIREFOX_NIGHTLY');
|
||||
}
|
||||
case Browser.CHROME:
|
||||
switch (tag as BrowserTag) {
|
||||
case BrowserTag.LATEST:
|
||||
return await chrome.resolveRevision(platform, 'latest');
|
||||
}
|
||||
}
|
||||
// We assume the tag is the revision if it didn't match any keywords.
|
||||
return tag;
|
||||
|
@ -16,6 +16,8 @@
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import {httpRequest} from '../httpUtil.js';
|
||||
|
||||
import {BrowserPlatform} from './types.js';
|
||||
|
||||
function archive(platform: BrowserPlatform, revision: string): string {
|
||||
@ -79,3 +81,40 @@ export function relativeExecutablePath(
|
||||
return path.join('chrome-win', 'chrome.exe');
|
||||
}
|
||||
}
|
||||
|
||||
export async function resolveRevision(
|
||||
platform: BrowserPlatform,
|
||||
// We will need it for other channels/keywords.
|
||||
_channel: 'latest' = 'latest'
|
||||
): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = httpRequest(
|
||||
new URL(
|
||||
`https://storage.googleapis.com/chromium-browser-snapshots/${folder(
|
||||
platform
|
||||
)}/LAST_CHANGE`
|
||||
),
|
||||
'GET',
|
||||
response => {
|
||||
let data = '';
|
||||
if (response.statusCode && response.statusCode >= 400) {
|
||||
return reject(new Error(`Got status code ${response.statusCode}`));
|
||||
}
|
||||
response.on('data', chunk => {
|
||||
data += chunk;
|
||||
});
|
||||
response.on('end', () => {
|
||||
try {
|
||||
return resolve(String(data));
|
||||
} catch {
|
||||
return reject(new Error('Chrome version not found'));
|
||||
}
|
||||
});
|
||||
},
|
||||
false
|
||||
);
|
||||
request.on('error', err => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -83,4 +83,15 @@ describe('CLI', function () {
|
||||
'--platform=linux',
|
||||
]);
|
||||
});
|
||||
|
||||
it('should download latest Chrome binaries', async () => {
|
||||
await new CLI(tmpDir).run([
|
||||
'npx',
|
||||
'@puppeteer/browsers',
|
||||
'install',
|
||||
`chrome@latest`,
|
||||
`--path=${tmpDir}`,
|
||||
'--platform=linux',
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user