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

@testim/chrome-version

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@testim/chrome-version - npm Package Compare versions

Comparing version 1.0.7 to 1.1.0

.github/workflows/ci.yml

18

chrome-finder/darwin.js
const { execSync } = require('child_process');
const path = require('path');
const path = require('path').posix;
const { canAccess, newLineRegex, sort } = require('./util');
function darwin() {
function darwin(includeChromium = false) {
const suffixes = [
// '/Contents/MacOS/Google Chrome Canary',
'/Contents/MacOS/Google Chrome',
// '/Contents/MacOS/Chromium'
... includeChromium ? ['/Contents/MacOS/Chromium'] : []
];

@@ -20,4 +20,6 @@

`${LSREGISTER} -dump` +
' | grep -E -i \'(google chrome( canary)?|chromium).app$\'' +
' | awk \'{$1=""; print $0}\'')
' | grep -E -i \'(google chrome( canary)?' + (includeChromium ? '|chromium' : '') + ').app(\\s\\(0x[0-9a-f]+\\))?$\'' +
' | awk \'sub(/\\(0x[0-9a-f]+\\)/, "")\'' +
' | awk \'{$1=""; print $0}\'' +
' | awk \'{ gsub(/^[ \\t]+|[ \\t]+$/, ""); print }\'')
.toString()

@@ -36,9 +38,9 @@ .split(newLineRegex)

const priorities = [
// { regex: new RegExp(`^${process.env.HOME}/Applications/.*Chromium.app`), weight: 49 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chromium.app`), weight: 49 },
{ regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome.app`), weight: 50 },
// { regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome Canary.app`), weight: 51 },
// { regex: /^\/Applications\/.*Chromium.app/, weight: 99 },
{ regex: /^\/Applications\/.*Chromium.app/, weight: 99 },
{ regex: /^\/Applications\/.*Chrome.app/, weight: 100 },
// { regex: /^\/Applications\/.*Chrome Canary.app/, weight: 101 },
// { regex: /^\/Volumes\/.*Chromium.app/, weight: -3 },
{ regex: /^\/Volumes\/.*Chromium.app/, weight: -3 },
{ regex: /^\/Volumes\/.*Chrome.app/, weight: -2 },

@@ -45,0 +47,0 @@ // { regex: /^\/Volumes\/.*Chrome Canary.app/, weight: -1 }

@@ -6,9 +6,13 @@ 'use strict';

/**
* find a executable chrome for all support system
* @returns {string} executable chrome full path
* Find a executable Chrome (or Chromium) for all supported systems.
*
* Supports macOS, Linux, and Windows.
*
* @param {boolean} includeChromium true if we should consider Chromium in our search, false otherwise.
* @returns {string} the first full path to an executable Chrome (or Chromium)
* @throws
* if no executable chrome find, ERROR_NO_INSTALLATIONS_FOUND will be throw
* if no executable Chrome (or Chromium) find, ERROR_NO_INSTALLATIONS_FOUND will be throw
* if platform is not one if ['win32','darwin','linux'], ERROR_PLATFORM_NOT_SUPPORT will be throw
*/
function findChrome() {
function findChrome(includeChromium = false) {
const { platform } = process;

@@ -18,9 +22,9 @@ let installations = [];

case 'win32':
installations = require('./win32')();
installations = require('./win32')(includeChromium);
break;
case 'darwin':
installations = require('./darwin')();
installations = require('./darwin')(includeChromium);
break;
case 'linux':
installations = require('./linux')();
installations = require('./linux')(includeChromium);
break;

@@ -27,0 +31,0 @@ default:

const { execSync, execFileSync } = require('child_process');
const path = require('path');
const path = require('path').posix;
const fs = require('fs');

@@ -7,5 +7,5 @@ const { canAccess, sort, isExecutable, newLineRegex } = require('./util');

function findChromeExecutablesForLinuxDesktop(folder) {
function findChromeExecutablesForLinuxDesktop(folder, includeChromium = false) {
const argumentsRegex = /(^[^ ]+).*/; // Take everything up to the first space
const chromeExecRegex = '^Exec=\/.*\/(google|chrome|chromium)-.*';
const chromeExecRegex = '^Exec=\/.*\/(google|chrome' + (includeChromium ? '|chromium' : '') + ')-.*';

@@ -31,44 +31,15 @@ let installations = [];

/**
* Look for linux executables in 2 ways
* 1. Look into the directories where .desktop are saved on gnome based distro's
* 2. Look for google-chrome-stable & google-chrome executables by using the which command
*/
function linux() {
let installations = [];
// 2. Look into the directories where .desktop are saved on gnome based distro's
const desktopInstallationFolders = [
path.join(require('os').homedir(), '.local/share/applications/'),
'/usr/share/applications/',
];
desktopInstallationFolders.forEach(folder => {
installations = installations.concat(findChromeExecutablesForLinuxDesktop(folder));
});
// Look for google-chrome-stable & google-chrome executables by using the which command
function findChromeExecutablesForLinux(validChromePaths, includeChromium = false) {
const executables = [
'google-chrome-stable',
'google-chrome',
// 'chromium',
// 'chromium-browser',
// 'chromium/chrome', // on toradex machines "chromium" is a directory. seen on Angstrom v2016.12
... includeChromium ? ['chromium', 'chromium-browser', 'chromium/chrome'] : [] // chromium/chrome is for toradex machines where "chromium" is a directory. seen on Angstrom v2016.12
];
executables.forEach((executable) => {
// see http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/
const validChromePaths = [
'/usr/bin',
'/usr/local/bin',
'/usr/sbin',
'/usr/local/sbin',
'/opt/bin',
'/usr/bin/X11',
'/usr/X11R6/bin'
].map((possiblePath) => {
return executables.map(executable => {
const existingPaths = validChromePaths.map(possiblePath => {
try {
const chromePathToTest = possiblePath + '/' + executable;
if (fs.existsSync(chromePathToTest) && canAccess(chromePathToTest) && isExecutable(chromePathToTest)) {
installations.push(chromePathToTest);
return chromePathToTest;
return [ chromePathToTest ];
}

@@ -78,15 +49,14 @@ } catch (err) {

}
return undefined;
}).filter((foundChromePath) => foundChromePath);
return [];
}).reduce((acc, val) => acc.concat(val), []); //.filter((foundChromePath) => foundChromePath);
// skip asking "which" command if the binary was found by searching the known paths.
if (validChromePaths && validChromePaths.length > 0) {
return;
if (existingPaths && existingPaths.length > 0) {
return existingPaths;
}
try {
const chromePath =
execFileSync('which', [executable]).toString().split(newLineRegex)[0];
const chromePath = execFileSync('which', [executable]).toString().split(newLineRegex)[0];
if (canAccess(chromePath)) {
installations.push(chromePath);
return [ chromePath ];
}

@@ -96,10 +66,45 @@ } catch (err) {

}
return [];
}).reduce((acc, val) => acc.concat(val), []);
}
/**
* Look for linux executables in 2 ways
* 1. Look into the directories where .desktop are saved on gnome based distro's
* 2. Look for google-chrome-stable and google-chrome executables by using the which command
* If includeChromium is set, also look for chromium, chromium-browser, and chromium/chrome executables by using the which command
*/
function linux(includeChromium = false) {
let installations = [];
// 1. Look into the directories where .desktop are saved on gnome based distro's
const desktopInstallationFolders = [
path.join(require('os').homedir(), '.local/share/applications/'),
'/usr/share/applications/',
];
desktopInstallationFolders.forEach(folder => {
installations = installations.concat(findChromeExecutablesForLinuxDesktop(folder, includeChromium));
});
// 2. Look for google-chrome-stable and google-chrome (and optionally chromium, chromium-browser, and chromium-chrome) executables by using the which command
// see http://tldp.org/LDP/Linux-Filesystem-Hierarchy/html/
const validChromePaths = [
'/usr/bin',
'/usr/local/bin',
'/usr/sbin',
'/usr/local/sbin',
'/opt/bin',
'/usr/bin/X11',
'/usr/X11R6/bin'
];
installations = installations.concat(findChromeExecutablesForLinux(validChromePaths, includeChromium));
const priorities = [
// { regex: /chromium$/, weight: 52 },
{ regex: /chromium$/, weight: 52 },
{ regex: /chrome-wrapper$/, weight: 51 },
{ regex: /google-chrome-stable$/, weight: 50 },
{ regex: /google-chrome$/, weight: 49 },
// { regex: /chromium-browser$/, weight: 48 },
{ regex: /chromium-browser$/, weight: 48 },
{ regex: /chrome$/, weight: 47 },

@@ -106,0 +111,0 @@ ];

@@ -1,5 +0,7 @@

const path = require('path');
const path = require('path').win32;
const { canAccess } = require('./util');
const procesEnv = process.env;
function win32() {
function win32(includeChromium = false) {
const installations = [];

@@ -10,14 +12,15 @@ const suffixes = [

'\\chrome-win32\\chrome.exe',
'\\Chromium\\Application\\chrome.exe',
... includeChromium ? ['\\Chromium\\Application\\chrome.exe'] : [],
// '\\Google\\Chrome Beta\\Application\\chrome.exe',
];
const prefixes =
[process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']];
const prefixes = [
procesEnv.LOCALAPPDATA,
procesEnv.PROGRAMFILES,
procesEnv['PROGRAMFILES(X86)']
].filter(prefix => prefix); // filter out undefined
prefixes.forEach(prefix => suffixes.forEach(suffix => {
if (prefix) {
const chromePath = path.join(prefix, suffix);
if (canAccess(chromePath)) {
installations.push(chromePath);
}
const chromePath = path.join(prefix, suffix);
if (canAccess(chromePath)) {
installations.push(chromePath);
}

@@ -24,0 +27,0 @@ }));

@@ -1,2 +0,2 @@

"use strict";
'use strict';

@@ -10,7 +10,7 @@ const findChrome = require('./chrome-finder');

async function getChromeVersionFromCli() {
async function getChromeVersionFromCli(includeChromium) {
let chromePath;
try {
chromePath = findChrome();
chromePath = findChrome(includeChromium);
} catch (err) {

@@ -22,12 +22,15 @@ return null;

const version = res.stdout.substr(14).trim();
const version = extractChromeVersionNumer(res.stdout);
return version;
}
function extractChromeVersionNumer(chromeVersionString) {
return chromeVersionString.replace(/.+\s([0-9]+(\.[0-9]+)*)\s?.*/, '$1');
}
async function getChromeVersionWin() {
async function getChromeVersionWin(includeChromium) {
let chromePath;
try {
chromePath = findChrome();
chromePath = findChrome(includeChromium);
} catch (err) {

@@ -50,3 +53,4 @@ return null;

function getChromeVersionFromOsa() {
function getChromeVersionFromOsa(includeChromium) {
try {

@@ -56,2 +60,12 @@ const version = execSync('osascript -e \'tell application "Google Chrome" to get version\'').toString().trim();

} catch (err) {
if (!includeChromium) {
return null;
}
// else fall-through to check for Chromium below
}
try {
const version = execSync('osascript -e \'tell application "Chromium" to get version\'').toString().trim();
return version;
} catch (err) {
return null;

@@ -61,9 +75,17 @@ }

async function getChromeVersion() {
/**
* Gets the version of Chrome (or Chromium) that is installed.
*
* Supports macOS, Linux, and Windows.
*
* @param {boolean} includeChromium true if we should consider Chromium in our search, false otherwise.
* @returns {string} the version number of Chrome (or Chromium), or null if the OS is not supported.
*/
async function getChromeVersion(includeChromium = false) {
const os = process.platform;
if (os === 'darwin') return getChromeVersionFromOsa();
if (os === 'linux') return getChromeVersionFromCli();
if (os.includes('win')) return getChromeVersionWin();
if (os === 'darwin') return getChromeVersionFromOsa(includeChromium);
if (os === 'linux') return getChromeVersionFromCli(includeChromium);
if (os.includes('win')) return getChromeVersionWin(includeChromium);

@@ -70,0 +92,0 @@ console.log(`${os} is not supported`);

{
"name": "@testim/chrome-version",
"version": "1.0.7",
"version": "1.1.0",
"description": "Finds the version of Chrome that is installed on your machine",
"main": "index.js",
"scripts": {
"lint": "eslint *.js --fix"
"lint": "eslint *.js --fix",
"test": "mocha"
},
"author": "Elad Katz",
"repository": {
"type": "git",
"url": "https://github.com/testimio/chrome-version.git"
},
"author": "Testim",
"license": "MIT",
"homepage": "https://github.com/testimio/chrome-version",
"keywords": ["chrome", "version" ],
"keywords": [
"chrome",
"version"
],
"devDependencies": {
"eslint": "^6.4.0"
"chai": "4.3.4",
"eslint": "8.7.0",
"mocha": "8.4.0",
"rewire": "6.0.0"
}
}
# chrome-version
Finds the version of Chrome that is installed on your machine.
[![Build Status](https://github.com/testimio/chrome-version/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/testimio/chrome-version/actions/workflows/ci.yml)
Finds the version of Chrome (or Chromium) that is installed on your machine.
## Installation

@@ -14,3 +16,4 @@ ```sh

const { getChromeVersion } = require('chrome-version');
const version = await getChromeVersion();
const includeChromium = false; // NOTE: set to true to also search for Chromium
const version = await getChromeVersion(includeChromium);
console.log(version);

@@ -20,2 +23,7 @@ })();

## Testing
```sh
npm test
```
* If no version of chrome is installed on your machine `getChromeVersion` will return null.
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