chromedriver
Advanced tools
Comparing version 2.26.1 to 2.26.2
@@ -23,2 +23,3 @@ 'use strict'; | ||
var chromedriver_version = process.env.npm_config_chromedriver_version || process.env.CHROMEDRIVER_VERSION || helper.version; | ||
if (platform === 'linux') { | ||
@@ -48,7 +49,3 @@ if (process.arch === 'x64') { | ||
downloadUrl = util.format(downloadUrl, helper.version, platform); | ||
var fileName = downloadUrl.split('/').pop(); | ||
npmconf.load(function(err, conf) { | ||
npmconf.load(function (err, conf) { | ||
if (err) { | ||
@@ -62,10 +59,18 @@ console.log('Error loading npm config'); | ||
var tmpPath = findSuitableTempDirectory(conf); | ||
var downloadedFile = path.join(tmpPath, fileName); | ||
var downloadedFile = ''; | ||
var promise = kew.resolve(true); | ||
promise = promise.then(function () { | ||
if (chromedriver_version === 'LATEST') | ||
return getLatestVersion(getRequestOptions(conf, cdnUrl + '/LATEST_RELEASE')); | ||
}); | ||
// Start the install. | ||
promise = promise.then(function () { | ||
downloadUrl = util.format(downloadUrl, chromedriver_version, platform); | ||
var fileName = downloadUrl.split('/').pop(); | ||
downloadedFile = path.join(tmpPath, fileName); | ||
console.log('Downloading', downloadUrl); | ||
console.log('Saving to', downloadedFile); | ||
return requestBinary(getRequestOptions(conf), downloadedFile); | ||
return requestBinary(getRequestOptions(conf, downloadUrl), downloadedFile); | ||
}); | ||
@@ -76,15 +81,15 @@ | ||
}) | ||
.then(function () { | ||
return copyIntoPlace(tmpPath, libPath); | ||
}) | ||
.then(function () { | ||
return fixFilePermissions(); | ||
}) | ||
.then(function () { | ||
console.log('Done. ChromeDriver binary available at', helper.path); | ||
}) | ||
.fail(function (err) { | ||
console.error('ChromeDriver installation failed', err); | ||
process.exit(1); | ||
}); | ||
.then(function () { | ||
return copyIntoPlace(tmpPath, libPath); | ||
}) | ||
.then(function () { | ||
return fixFilePermissions(); | ||
}) | ||
.then(function () { | ||
console.log('Done. ChromeDriver binary available at', helper.path); | ||
}) | ||
.fail(function (err) { | ||
console.error('ChromeDriver installation failed', err); | ||
process.exit(1); | ||
}); | ||
}); | ||
@@ -120,3 +125,3 @@ | ||
function getRequestOptions(conf) { | ||
function getRequestOptions(conf, downloadPath) { | ||
var options = url.parse(downloadUrl); | ||
@@ -126,4 +131,4 @@ var proxyUrl = options.protocol === 'https:' ? conf.get('https-proxy') : conf.get('proxy'); | ||
options = url.parse(proxyUrl); | ||
options.path = downloadUrl; | ||
options.headers = { Host: url.parse(downloadUrl).host }; | ||
options.path = downloadPath; | ||
options.headers = { Host: url.parse(downloadPath).host }; | ||
// Turn basic authorization into proxy-authorization. | ||
@@ -135,3 +140,3 @@ if (options.auth) { | ||
} else { | ||
options = url.parse(downloadUrl); | ||
options = url.parse(downloadPath); | ||
} | ||
@@ -145,3 +150,3 @@ | ||
try { | ||
ca = fs.readFileSync(process.env.npm_config_cafile, {encoding: 'utf8'}) | ||
ca = fs.readFileSync(process.env.npm_config_cafile, { encoding: 'utf8' }) | ||
.split(/\n(?=-----BEGIN CERTIFICATE-----)/g); | ||
@@ -172,2 +177,26 @@ | ||
function getLatestVersion(requestOptions) { | ||
var deferred = kew.defer(); | ||
var protocol = requestOptions.protocol === 'https:' ? https : http; | ||
var client = protocol.get(requestOptions, function (response) { | ||
var body = ''; | ||
if (response.statusCode === 200) { | ||
response.addListener('data', function (data) { | ||
body += data; | ||
}); | ||
response.addListener('end', function () { | ||
try { | ||
chromedriver_version = JSON.parse(body); | ||
} catch (err) { | ||
deferred.reject('Unable to parse response as JSON', err); | ||
} | ||
deferred.resolve(true); | ||
}); | ||
} else { | ||
client.abort(); | ||
deferred.reject('Error with ' + requestOptions.protocol + ' request: ' + util.inspect(response.headers)); | ||
} | ||
}); | ||
return deferred.promise; | ||
} | ||
@@ -187,3 +216,3 @@ function requestBinary(requestOptions, filePath) { | ||
if (status === 200) { | ||
response.addListener('data', function (data) { | ||
response.addListener('data', function (data) { | ||
fs.writeSync(outFile, data, 0, data.length, null); | ||
@@ -197,3 +226,3 @@ count += data.length; | ||
response.addListener('end', function () { | ||
response.addListener('end', function () { | ||
console.log('Received ' + Math.floor(count / 1024) + 'K total.'); | ||
@@ -244,3 +273,3 @@ fs.closeSync(outFile); | ||
var writer = fs.createWriteStream(targetFile); | ||
writer.on("close", function() { | ||
writer.on("close", function () { | ||
deferred.resolve(true); | ||
@@ -247,0 +276,0 @@ }); |
{ | ||
"name": "chromedriver", | ||
"version": "2.26.1", | ||
"version": "2.26.2", | ||
"keywords": [ | ||
@@ -5,0 +5,0 @@ "chromedriver", |
@@ -120,3 +120,16 @@ ChromeDriver | ||
with an additional build number that is used for revisions to the installer. | ||
For Latest version of Chromdriver | ||
Or add property into your [`.npmrc`](https://docs.npmjs.com/files/npmrc) file. | ||
``` | ||
chromedriver_version=LATEST | ||
``` | ||
Another option is to use env variable `CHROMEDRIVER_VERSION`. | ||
```shell | ||
CHROMEDRIVER_VERSION=LATEST npm install chromedriver | ||
``` | ||
A Note on chromedriver | ||
@@ -123,0 +136,0 @@ ------------------- |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22179
433
162
13