puppeteer
Advanced tools
Comparing version 1.0.0-next.1517875514795 to 1.0.0-next.1518024831019
@@ -28,12 +28,12 @@ /** | ||
const Downloader = require('./lib/Downloader'); | ||
const downloader = Downloader.createDefault(); | ||
const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host; | ||
const platform = downloader.currentPlatform(); | ||
const revision = Downloader.defaultRevision(); | ||
const ProgressBar = require('progress'); | ||
const puppeteer = require('./index'); | ||
const browserFetcher = puppeteer.createBrowserFetcher({ host: downloadHost }); | ||
const revisionInfo = downloader.revisionInfo(platform, revision); | ||
const revision = require('./package.json').puppeteer.chromium_revision; | ||
const revisionInfo = browserFetcher.revisionInfo(revision); | ||
// Do nothing if the revision is already downloaded. | ||
if (revisionInfo.downloaded) | ||
if (revisionInfo.local) | ||
return; | ||
@@ -53,7 +53,4 @@ | ||
const allRevisions = downloader.downloadedRevisions(); | ||
const downloadHost = process.env.PUPPETEER_DOWNLOAD_HOST || process.env.npm_config_puppeteer_download_host; | ||
if (downloadHost) | ||
downloader.setDownloadHost(downloadHost); | ||
downloader.downloadRevision(platform, revision, onProgress) | ||
browserFetcher.download(revisionInfo.revision, onProgress) | ||
.then(() => browserFetcher.localRevisions()) | ||
.then(onSuccess) | ||
@@ -63,8 +60,10 @@ .catch(onError); | ||
/** | ||
* @param {!Array<string>} | ||
* @return {!Promise} | ||
*/ | ||
function onSuccess() { | ||
function onSuccess(localRevisions) { | ||
console.log('Chromium downloaded to ' + revisionInfo.folderPath); | ||
localRevisions = localRevisions.filter(revision => revision !== revisionInfo.revision); | ||
// Remove previous chromium revisions. | ||
const cleanupOldVersions = allRevisions.map(({platform, revision}) => downloader.removeRevision(platform, revision)); | ||
const cleanupOldVersions = localRevisions.map(revision => browserFetcher.remove(revision)); | ||
return Promise.all(cleanupOldVersions); | ||
@@ -83,11 +82,15 @@ } | ||
let progressBar = null; | ||
function onProgress(bytesTotal, delta) { | ||
let lastDownloadedBytes = 0; | ||
function onProgress(downloadedBytes, totalBytes) { | ||
if (!progressBar) { | ||
progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(bytesTotal)} [:bar] :percent :etas `, { | ||
const ProgressBar = require('progress'); | ||
progressBar = new ProgressBar(`Downloading Chromium r${revision} - ${toMegabytes(totalBytes)} [:bar] :percent :etas `, { | ||
complete: '=', | ||
incomplete: ' ', | ||
width: 20, | ||
total: bytesTotal, | ||
total: totalBytes, | ||
}); | ||
} | ||
const delta = downloadedBytes - lastDownloadedBytes; | ||
lastDownloadedBytes = downloadedBytes; | ||
progressBar.tick(delta); | ||
@@ -94,0 +97,0 @@ } |
@@ -16,2 +16,4 @@ /** | ||
*/ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -21,2 +23,3 @@ const debugError = require('debug')(`puppeteer:error`); | ||
let apiCoverage = null; | ||
let projectRoot = null; | ||
class Helper { | ||
@@ -47,2 +50,13 @@ /** | ||
/** | ||
* @return {string} | ||
*/ | ||
static projectRoot() { | ||
if (!projectRoot) { | ||
// Project root will be different for node6-transpiled code. | ||
projectRoot = fs.existsSync(path.join(__dirname, '..', 'package.json')) ? path.join(__dirname, '..') : path.join(__dirname, '..', '..'); | ||
} | ||
return projectRoot; | ||
} | ||
/** | ||
* @param {!Object} exceptionDetails | ||
@@ -49,0 +63,0 @@ * @return {string} |
@@ -20,3 +20,3 @@ /** | ||
const childProcess = require('child_process'); | ||
const Downloader = require('./Downloader'); | ||
const BrowserFetcher = require('./BrowserFetcher'); | ||
const {Connection} = require('./Connection'); | ||
@@ -27,3 +27,3 @@ const {Browser} = require('./Browser'); | ||
const {helper} = require('./helper'); | ||
const ChromiumRevision = Downloader.defaultRevision(); | ||
const ChromiumRevision = require(path.join(helper.projectRoot(), 'package.json')).puppeteer.chromium_revision; | ||
@@ -95,5 +95,5 @@ const mkdtempAsync = helper.promisify(fs.mkdtemp); | ||
if (typeof chromeExecutable !== 'string') { | ||
const downloader = Downloader.createDefault(); | ||
const revisionInfo = downloader.revisionInfo(downloader.currentPlatform(), ChromiumRevision); | ||
console.assert(revisionInfo.downloaded, `Chromium revision is not downloaded. Run "npm install" or "yarn install"`); | ||
const browserFetcher = new BrowserFetcher(); | ||
const revisionInfo = browserFetcher.revisionInfo(ChromiumRevision); | ||
console.assert(revisionInfo.local, `Chromium revision is not downloaded. Run "npm install" or "yarn install"`); | ||
chromeExecutable = revisionInfo.executablePath; | ||
@@ -193,4 +193,4 @@ } | ||
static executablePath() { | ||
const downloader = Downloader.createDefault(); | ||
const revisionInfo = downloader.revisionInfo(downloader.currentPlatform(), ChromiumRevision); | ||
const browserFetcher = new BrowserFetcher(); | ||
const revisionInfo = browserFetcher.revisionInfo(ChromiumRevision); | ||
return revisionInfo.executablePath; | ||
@@ -197,0 +197,0 @@ } |
@@ -18,2 +18,3 @@ /** | ||
const Launcher = require('./Launcher'); | ||
const BrowserFetcher = require('./BrowserFetcher'); | ||
@@ -50,2 +51,10 @@ class Puppeteer { | ||
} | ||
/** | ||
* @param {!Object=} options | ||
* @return {!BrowserFetcher} | ||
*/ | ||
static createBrowserFetcher(options) { | ||
return new BrowserFetcher(options); | ||
} | ||
} | ||
@@ -52,0 +61,0 @@ |
{ | ||
"name": "puppeteer", | ||
"version": "1.0.0-next.1517875514795", | ||
"version": "1.0.0-next.1518024831019", | ||
"description": "A high-level API to control headless Chrome over the DevTools Protocol", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
259455
6525
25