Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chromedriver

Package Overview
Dependencies
Maintainers
1
Versions
223
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chromedriver - npm Package Compare versions

Comparing version 114.0.1 to 114.0.2

232

install.js
'use strict';
// @ts-check
const fs = require('fs');
const fs = require('node:fs');
const helper = require('./lib/chromedriver');
const axios = require('axios');
const path = require('path');
const child_process = require('child_process');
const os = require('os');
const url = require('url');
const https = require('https');
const { promisify } = require('util');
const { finished } = require('stream');
const path = require('node:path');
const child_process = require('node:child_process');
const os = require('node:os');
const url = require('node:url');
const https = require('node:https');
const { promisify } = require('node:util');
const { finished } = require('node:stream');
const extractZip = require('extract-zip');

@@ -22,4 +22,4 @@ const { getChromeVersion } = require('@testim/chrome-version');

const skipDownload = process.env.npm_config_chromedriver_skip_download || process.env.CHROMEDRIVER_SKIP_DOWNLOAD;
if (skipDownload === 'true') {
const skipDownload = (process.env.npm_config_chromedriver_skip_download || process.env.CHROMEDRIVER_SKIP_DOWNLOAD) === 'true';
if (skipDownload) {
console.log('Found CHROMEDRIVER_SKIP_DOWNLOAD variable, skipping installation.');

@@ -29,47 +29,46 @@ process.exit(0);

const libPath = path.join(__dirname, 'lib', 'chromedriver');
let cdnUrl = process.env.npm_config_chromedriver_cdnurl || process.env.CHROMEDRIVER_CDNURL || 'https://chromedriver.storage.googleapis.com';
const configuredfilePath = process.env.npm_config_chromedriver_filepath || process.env.CHROMEDRIVER_FILEPATH;
// adapt http://chromedriver.storage.googleapis.com/
cdnUrl = cdnUrl.replace(/\/+$/, '');
const detect_chromedriver_version = process.env.npm_config_detect_chromedriver_version || process.env.DETECT_CHROMEDRIVER_VERSION;
const include_chromium = (process.env.npm_config_include_chromium || process.env.INCLUDE_CHROMIUM) === 'true';
let chromedriver_version = process.env.npm_config_chromedriver_version || process.env.CHROMEDRIVER_VERSION || helper.version;
let chromedriverBinaryFilePath;
let downloadedFile = '';
let platform = '';
(async function install() {
let cdnUrl = process.env.npm_config_chromedriver_cdnurl || process.env.CHROMEDRIVER_CDNURL || 'https://googlechromelabs.github.io';
const legacyCdnUrl = process.env.npm_config_chromedriver_legacy_cdnurl || process.env.CHROMEDRIVER_LEGACY_CDNURL || 'https://chromedriver.storage.googleapis.com';
// adapt http://chromedriver.storage.googleapis.com/
cdnUrl = cdnUrl.replace(/\/+$/, '');
let chromedriverVersion = process.env.npm_config_chromedriver_version || process.env.CHROMEDRIVER_VERSION || helper.version;
const detectChromedriverVersion = (process.env.npm_config_detect_chromedriver_version || process.env.DETECT_CHROMEDRIVER_VERSION) === 'true';
try {
if (detect_chromedriver_version === 'true') {
if (detectChromedriverVersion) {
const includeChromium = (process.env.npm_config_include_chromium || process.env.INCLUDE_CHROMIUM) === 'true';
// Refer http://chromedriver.chromium.org/downloads/version-selection
const chromeVersion = await getChromeVersion(include_chromium);
const chromeVersion = await getChromeVersion(includeChromium);
console.log("Your Chrome version is " + chromeVersion);
const versionMatch = /^(.*?)\.\d+$/.exec(chromeVersion);
if (versionMatch) {
const chromeVersionWithoutPatch = versionMatch[1];
await getChromeDriverVersion(getRequestOptions(cdnUrl + '/LATEST_RELEASE_' + chromeVersionWithoutPatch));
console.log("Compatible ChromeDriver version is " + chromedriver_version);
chromedriverVersion = await getChromeDriverVersion(cdnUrl, legacyCdnUrl, parseInt(versionMatch[1]));
console.log("Compatible ChromeDriver version is " + chromedriverVersion);
}
}
if (chromedriver_version === 'LATEST') {
await getChromeDriverVersion(getRequestOptions(`${cdnUrl}/LATEST_RELEASE`));
} else if (chromedriverVersion === 'LATEST') {
chromedriverVersion = await getChromeDriverVersion(cdnUrl, legacyCdnUrl);
} else {
const latestReleaseForVersionMatch = chromedriver_version.match(/LATEST_(\d+)/);
const latestReleaseForVersionMatch = chromedriverVersion.match(/LATEST_(\d+)/);
if (latestReleaseForVersionMatch) {
const majorVersion = latestReleaseForVersionMatch[1];
await getChromeDriverVersion(getRequestOptions(`${cdnUrl}/LATEST_RELEASE_${majorVersion}`));
chromedriverVersion = await getChromeDriverVersion(cdnUrl, legacyCdnUrl, parseInt(latestReleaseForVersionMatch[1]));
}
}
platform = validatePlatform();
const tmpPath = findSuitableTempDirectory();
let tmpPath = findSuitableTempDirectory(chromedriverVersion);
const extractDirectory = tmpPath;
const majorVersion = parseInt(chromedriverVersion.split('.')[0]);
const useLegacyMethod = majorVersion <= 114;
const platform = getPlatform(chromedriverVersion);
const downloadedFile = getDownloadFilePath(useLegacyMethod, tmpPath, platform);
if (!useLegacyMethod) {
tmpPath = path.join(tmpPath, path.basename(downloadedFile, path.extname(downloadedFile)));
}
const chromedriverBinaryFileName = process.platform === 'win32' ? 'chromedriver.exe' : 'chromedriver';
chromedriverBinaryFilePath = path.resolve(tmpPath, chromedriverBinaryFileName);
const chromedriverIsAvailable = await verifyIfChromedriverIsAvailableAndHasCorrectVersion();
const chromedriverBinaryFilePath = path.resolve(tmpPath, chromedriverBinaryFileName);
const chromedriverIsAvailable = await verifyIfChromedriverIsAvailableAndHasCorrectVersion(chromedriverVersion, chromedriverBinaryFilePath);
if (!chromedriverIsAvailable) {
console.log('Current existing ChromeDriver binary is unavailable, proceeding with download and extraction.');
await downloadFile(tmpPath);
await extractDownload(tmpPath);
await downloadFile(useLegacyMethod ? legacyCdnUrl : cdnUrl, useLegacyMethod, downloadedFile, chromedriverVersion, platform, detectChromedriverVersion);
await extractDownload(extractDirectory, chromedriverBinaryFilePath, downloadedFile);
}
const libPath = path.join(__dirname, 'lib', 'chromedriver');
await copyIntoPlace(tmpPath, libPath);

@@ -84,8 +83,10 @@ fixFilePermissions();

function validatePlatform() {
/** @type string */
let thePlatform = process.platform;
/**
* @param {string} chromedriverVersion
*/
function getPlatform(chromedriverVersion) {
const thePlatform = process.platform;
if (thePlatform === 'linux') {
if (process.arch === 'arm64' || process.arch === 's390x' || process.arch === 'x64') {
thePlatform += '64';
return 'linux64';
} else {

@@ -96,3 +97,3 @@ console.log('Only Linux 64 bits supported.');

} else if (thePlatform === 'darwin' || thePlatform === 'freebsd') {
const osxPlatform = getMacOsRealArch();
const osxPlatform = getMacOsRealArch(chromedriverVersion);

@@ -104,28 +105,59 @@ if (!osxPlatform) {

thePlatform = osxPlatform;
} else if (thePlatform !== 'win32') {
console.log('Unexpected platform or architecture:', process.platform, process.arch);
process.exit(1);
return osxPlatform;
} else if (thePlatform === 'win32') {
if (compareVersions(chromedriverVersion, '115') < 0) {
return 'win32';
}
return (process.arch === 'x64') ? 'win64' : 'win32';
}
return thePlatform;
console.log('Unexpected platform or architecture:', process.platform, process.arch);
process.exit(1);
}
async function downloadFile(dirToLoadTo) {
if (detect_chromedriver_version !== 'true' && configuredfilePath) {
downloadedFile = configuredfilePath;
console.log('Using file: ', downloadedFile);
return;
/**
* @param {string} cdnUrl
* @param {boolean} useLegacyDownloadMethod
* @param {string} downloadedFile
* @param {string} chromedriverVersion
* @param {string} platform
* @param {boolean} detectChromedriverVersion
*/
async function downloadFile(cdnUrl, useLegacyDownloadMethod, downloadedFile, chromedriverVersion, platform, detectChromedriverVersion) {
const configuredfilePath = process.env.npm_config_chromedriver_filepath || process.env.CHROMEDRIVER_FILEPATH;
if (detectChromedriverVersion && configuredfilePath) {
console.log('Using file: ', configuredfilePath);
return configuredfilePath;
} else {
const fileName = `chromedriver_${platform}.zip`;
const tempDownloadedFile = path.resolve(dirToLoadTo, fileName);
downloadedFile = tempDownloadedFile;
const formattedDownloadUrl = `${cdnUrl}/${chromedriver_version}/${fileName}`;
console.log('Downloading from file: ', formattedDownloadUrl);
console.log('Saving to file:', downloadedFile);
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
const fileName = path.basename(downloadedFile);
if (useLegacyDownloadMethod) {
const formattedDownloadUrl = `${cdnUrl}/${chromedriverVersion}/${fileName}`;
console.log('Downloading from file: ', formattedDownloadUrl);
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
} else {
const dlBaseUrl = 'https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing'; // todo: make this configurable?
const formattedDownloadUrl = `${dlBaseUrl}/${chromedriverVersion}/${platform}/${fileName}`;
console.log('Downloading from file: ', formattedDownloadUrl);
await requestBinary(getRequestOptions(formattedDownloadUrl), downloadedFile);
}
}
}
function verifyIfChromedriverIsAvailableAndHasCorrectVersion() {
/**
* @param {any} useLegacyPath
* @param {string} dirToLoadTo
* @param {string} platform
*/
function getDownloadFilePath(useLegacyPath, dirToLoadTo, platform) {
const fileName = useLegacyPath ? `chromedriver_${platform}.zip` : `chromedriver-${platform}.zip`;
const downloadedFile = path.resolve(dirToLoadTo, fileName);
console.log('Saving to file:', downloadedFile);
return downloadedFile;
}
/**
* @param {string} chromedriverVersion
* @param {string} chromedriverBinaryFilePath
*/
function verifyIfChromedriverIsAvailableAndHasCorrectVersion(chromedriverVersion, chromedriverBinaryFilePath) {
if (!fs.existsSync(chromedriverBinaryFilePath))

@@ -150,3 +182,3 @@ return Promise.resolve(false);

return deferred.resolve(false);
if (parts[1].startsWith(chromedriver_version)) {
if (parts[1].startsWith(chromedriverVersion)) {
console.log(`ChromeDriver is already available at '${chromedriverBinaryFilePath}'.`);

@@ -164,3 +196,6 @@ return deferred.resolve(true);

function findSuitableTempDirectory() {
/**
* @param {string} chromedriverVersion
*/
function findSuitableTempDirectory(chromedriverVersion) {
const now = Date.now();

@@ -177,3 +212,3 @@ const candidateTmpDirs = [

if (!tempDir) continue;
const namespace = chromedriver_version;
const namespace = chromedriverVersion;
const candidatePath = path.join(tempDir, namespace, 'chromedriver');

@@ -253,11 +288,34 @@ try {

/**
*
* @param {import('axios').AxiosRequestConfig} requestOptions
* @param {string} cdnUrl
* @param {string} legacyCdnUrl
* @param {number} [majorVersion]
* @returns {Promise<string>}
*/
async function getChromeDriverVersion(requestOptions) {
console.log('Finding Chromedriver version.');
// @ts-expect-error
const response = await axios.request(requestOptions);
chromedriver_version = response.data.trim();
console.log(`Chromedriver version is ${chromedriver_version}.`);
async function getChromeDriverVersion(cdnUrl, legacyCdnUrl, majorVersion) {
if (majorVersion == null || majorVersion > 114) {
console.log('Finding Chromedriver version.');
let chromedriverVersion;
if (majorVersion) {
const requestOptions = getRequestOptions(`${cdnUrl}/chrome-for-testing/latest-versions-per-milestone.json`);
// @ts-expect-error
const response = await axios.request(requestOptions);
chromedriverVersion = response.data?.milestones[majorVersion.toString()]?.version;
} else {
const requestOptions = getRequestOptions(`${cdnUrl}/chrome-for-testing/last-known-good-versions.json`);
// @ts-expect-error
const response = await axios.request(requestOptions);
chromedriverVersion = response.data?.channels?.Stable?.version;
}
console.log(`Chromedriver version is ${chromedriverVersion}.`);
return chromedriverVersion;
} else {
console.log('Finding Chromedriver version using legacy method.');
const urlPath = majorVersion ? `LATEST_RELEASE_${majorVersion}` : 'LATEST_RELEASE';
const requestOptions = getRequestOptions(`${legacyCdnUrl}/${urlPath}`);
// @ts-expect-error
const response = await axios.request(requestOptions);
const chromedriverVersion = response.data.trim();
console.log(`Chromedriver version is ${chromedriverVersion}.`);
return chromedriverVersion;
}
}

@@ -308,3 +366,8 @@

async function extractDownload(dirToExtractTo) {
/**
* @param {string} dirToExtractTo
* @param {string} chromedriverBinaryFilePath
* @param {string} downloadedFile
*/
async function extractDownload(dirToExtractTo, chromedriverBinaryFilePath, downloadedFile) {
if (path.extname(downloadedFile) !== '.zip') {

@@ -323,2 +386,6 @@ fs.copyFileSync(downloadedFile, chromedriverBinaryFilePath);

/**
* @param {string} originPath
* @param {string} targetPath
*/
async function copyIntoPlace(originPath, targetPath) {

@@ -359,13 +426,14 @@ fs.rmSync(targetPath, { recursive: true, force: true });

function getMacOsRealArch() {
/**
* @param {string} chromedriverVersion
*/
function getMacOsRealArch(chromedriverVersion) {
if (process.arch === 'arm64' || isEmulatedRosettaEnvironment()) {
if (compareVersions(chromedriver_version, '106.0.5249.61') < 0) {
return 'mac64_m1';
}
return 'mac_arm64';
return compareVersions(chromedriverVersion, '106.0.5249.61') < 0
? 'mac64_m1'
: compareVersions(chromedriverVersion, '115') < 0 ? 'mac_arm64' : 'mac-arm64';
}
if (process.arch === 'x64') {
return 'mac64';
return compareVersions(chromedriverVersion, '115') < 0 ? 'mac64' : 'mac-x64';
}

@@ -372,0 +440,0 @@

{
"name": "chromedriver",
"version": "114.0.1",
"version": "114.0.2",
"keywords": [

@@ -32,4 +32,4 @@ "chromedriver",

"@testim/chrome-version": "^1.1.3",
"axios": "^1.2.1",
"compare-versions": "^5.0.1",
"axios": "^1.4.0",
"compare-versions": "^5.0.3",
"extract-zip": "^2.0.1",

@@ -41,4 +41,4 @@ "https-proxy-agent": "^5.0.1",

"devDependencies": {
"eslint": "^8.29.0",
"typescript": "^4.9.3"
"eslint": "^8.42.0",
"typescript": "^5.1.3"
},

@@ -48,2 +48,2 @@ "engines": {

}
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc