feat(install): add environment variable to overwrite host part of url (#958)
This patch adds PUPPETEER_DOWNLOAD_HOST env variable that allows to specify a download host. Useful for downloading from mirrors. Fixes #951
This commit is contained in:
parent
c9e1a2de4e
commit
945a826a0b
@ -210,6 +210,7 @@ Puppeteer looks for certain [environment variables](https://en.wikipedia.org/wik
|
||||
|
||||
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run Chromium.
|
||||
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
|
||||
- `PUPPETEER_DOWNLOAD_HOST` - overwrite host part of URL that is used to download Chromium
|
||||
|
||||
### class: Puppeteer
|
||||
|
||||
|
@ -42,7 +42,8 @@ if (NPM_HTTP_PROXY)
|
||||
process.env.HTTP_PROXY = NPM_HTTP_PROXY;
|
||||
|
||||
const allRevisions = Downloader.downloadedRevisions();
|
||||
Downloader.downloadRevision(platform, revision, onProgress)
|
||||
const DOWNLOAD_HOST = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host;
|
||||
Downloader.downloadRevision(platform, revision, DOWNLOAD_HOST, onProgress)
|
||||
.then(onSuccess)
|
||||
.catch(onError);
|
||||
|
||||
|
@ -28,12 +28,13 @@ const ProxyAgent = require('https-proxy-agent');
|
||||
const getProxyForUrl = require('proxy-from-env').getProxyForUrl;
|
||||
|
||||
const DOWNLOADS_FOLDER = path.join(__dirname, '..', '.local-chromium');
|
||||
const DEFAULT_DOWNLOAD_HOST = 'https://storage.googleapis.com';
|
||||
|
||||
const downloadURLs = {
|
||||
linux: 'https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
|
||||
mac: 'https://storage.googleapis.com/chromium-browser-snapshots/Mac/%d/chrome-mac.zip',
|
||||
win32: 'https://storage.googleapis.com/chromium-browser-snapshots/Win/%d/chrome-win32.zip',
|
||||
win64: 'https://storage.googleapis.com/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip',
|
||||
linux: '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip',
|
||||
mac: '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip',
|
||||
win32: '%s/chromium-browser-snapshots/Win/%d/chrome-win32.zip',
|
||||
win64: '%s/chromium-browser-snapshots/Win_x64/%d/chrome-win32.zip',
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
@ -66,7 +67,7 @@ module.exports = {
|
||||
canDownloadRevision: function(platform, revision) {
|
||||
console.assert(downloadURLs[platform], 'Unknown platform: ' + platform);
|
||||
|
||||
const options = requestOptions(util.format(downloadURLs[platform], revision), 'HEAD');
|
||||
const options = requestOptions(util.format(downloadURLs[platform], DEFAULT_DOWNLOAD_HOST, revision), 'HEAD');
|
||||
|
||||
let resolve;
|
||||
const promise = new Promise(x => resolve = x);
|
||||
@ -84,13 +85,14 @@ module.exports = {
|
||||
/**
|
||||
* @param {string} platform
|
||||
* @param {string} revision
|
||||
* @param {string} [downloadHost=DEFAULT_DOWNLOAD_HOST]
|
||||
* @param {?function(number, number)} progressCallback
|
||||
* @return {!Promise}
|
||||
*/
|
||||
downloadRevision: function(platform, revision, progressCallback) {
|
||||
downloadRevision: function(platform, revision, downloadHost = DEFAULT_DOWNLOAD_HOST, progressCallback) {
|
||||
let url = downloadURLs[platform];
|
||||
console.assert(url, `Unsupported platform: ${platform}`);
|
||||
url = util.format(url, revision);
|
||||
url = util.format(url, downloadHost, revision);
|
||||
const zipPath = path.join(DOWNLOADS_FOLDER, `download-${platform}-${revision}.zip`);
|
||||
const folderPath = getFolderPath(platform, revision);
|
||||
if (fs.existsSync(folderPath))
|
||||
@ -133,7 +135,7 @@ module.exports = {
|
||||
/**
|
||||
* @param {string} platform
|
||||
* @param {string} revision
|
||||
* @return {!{folderPath: string, executablePath: string, downloaded: boolean, url: string}}
|
||||
* @return {!{folderPath: string, executablePath: string, downloaded: boolean}}
|
||||
*/
|
||||
revisionInfo: function(platform, revision) {
|
||||
console.assert(downloadURLs[platform], `Unsupported platform: ${platform}`);
|
||||
@ -150,8 +152,7 @@ module.exports = {
|
||||
return {
|
||||
executablePath,
|
||||
folderPath,
|
||||
downloaded: fs.existsSync(folderPath),
|
||||
url: util.format(downloadURLs[platform], revision)
|
||||
downloaded: fs.existsSync(folderPath)
|
||||
};
|
||||
},
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user