mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: consider downloadHost as baseUrl (#9973)
This commit is contained in:
parent
de0cc3245e
commit
05a44afe5a
@ -63,6 +63,16 @@ export interface Options {
|
|||||||
downloadedBytes: number,
|
downloadedBytes: number,
|
||||||
totalBytes: number
|
totalBytes: number
|
||||||
) => void;
|
) => void;
|
||||||
|
/**
|
||||||
|
* Determines the host that will be used for downloading.
|
||||||
|
*
|
||||||
|
* @defaultValue Either
|
||||||
|
*
|
||||||
|
* - https://storage.googleapis.com/chromium-browser-snapshots or
|
||||||
|
* - https://archive.mozilla.org/pub/firefox/nightly/latest-mozilla-central
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
baseUrl?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type InstalledBrowser = {
|
export type InstalledBrowser = {
|
||||||
@ -82,7 +92,8 @@ export async function fetch(options: Options): Promise<InstalledBrowser> {
|
|||||||
const url = getDownloadUrl(
|
const url = getDownloadUrl(
|
||||||
options.browser,
|
options.browser,
|
||||||
options.platform,
|
options.platform,
|
||||||
options.buildId
|
options.buildId,
|
||||||
|
options.baseUrl
|
||||||
);
|
);
|
||||||
const fileName = url.toString().split('/').pop();
|
const fileName = url.toString().split('/').pop();
|
||||||
assert(fileName, `A malformed download URL was found: ${url}.`);
|
assert(fileName, `A malformed download URL was found: ${url}.`);
|
||||||
@ -131,14 +142,20 @@ export async function canFetch(options: Options): Promise<boolean> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return await headHttpRequest(
|
return await headHttpRequest(
|
||||||
getDownloadUrl(options.browser, options.platform, options.buildId)
|
getDownloadUrl(
|
||||||
|
options.browser,
|
||||||
|
options.platform,
|
||||||
|
options.buildId,
|
||||||
|
options.baseUrl
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDownloadUrl(
|
function getDownloadUrl(
|
||||||
browser: Browser,
|
browser: Browser,
|
||||||
platform: BrowserPlatform,
|
platform: BrowserPlatform,
|
||||||
buildId: string
|
buildId: string,
|
||||||
|
baseUrl?: string
|
||||||
): URL {
|
): URL {
|
||||||
return new URL(downloadUrls[browser](platform, buildId));
|
return new URL(downloadUrls[browser](platform, buildId, baseUrl));
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,8 @@ export async function downloadBrowser(): Promise<void> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let downloadHost = configuration.downloadHost;
|
||||||
|
|
||||||
let platform = detectBrowserPlatform();
|
let platform = detectBrowserPlatform();
|
||||||
if (!platform) {
|
if (!platform) {
|
||||||
throw new Error('The current platform is not supported.');
|
throw new Error('The current platform is not supported.');
|
||||||
@ -70,6 +72,19 @@ export async function downloadBrowser(): Promise<void> {
|
|||||||
PUPPETEER_REVISIONS[product === 'chrome' ? 'chromium' : 'firefox'] ||
|
PUPPETEER_REVISIONS[product === 'chrome' ? 'chromium' : 'firefox'] ||
|
||||||
'latest';
|
'latest';
|
||||||
|
|
||||||
|
if (product === 'chrome' && downloadHost) {
|
||||||
|
// TODO: remove downloadHost in favour of baseDownloadUrl. The "host" of
|
||||||
|
// Firefox is already a URL and not a host. This would be a breaking change.
|
||||||
|
if (
|
||||||
|
!downloadHost.endsWith('/chromium-browser-snapshots') &&
|
||||||
|
!downloadHost.endsWith('/chromium-browser-snapshots/')
|
||||||
|
) {
|
||||||
|
downloadHost += downloadHost.endsWith('/')
|
||||||
|
? 'chromium-browser-snapshots'
|
||||||
|
: '/chromium-browser-snapshots';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
|
const buildId = await resolveBuildId(browser, platform, unresolvedBuildId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -79,6 +94,7 @@ export async function downloadBrowser(): Promise<void> {
|
|||||||
platform,
|
platform,
|
||||||
buildId,
|
buildId,
|
||||||
downloadProgressCallback: makeProgressCallback(browser, buildId),
|
downloadProgressCallback: makeProgressCallback(browser, buildId),
|
||||||
|
baseUrl: downloadHost,
|
||||||
});
|
});
|
||||||
|
|
||||||
logPolitely(
|
logPolitely(
|
||||||
|
Loading…
Reference in New Issue
Block a user