chrome-location2
v4.1.0
Published
Approximates the current location of the Chrome browser across platforms.
Maintainers
Readme
Approximates the current location of the Chrome browser across platforms.
chrome-location2

- By default checks only
stable. Optionally can cascade tobeta/dev/canary. - Supports macOS / Windows / Linux
- Works both as an ES module or CommonJS
Installation
npm i chrome-location2Usage
Via Node.js (strict by default):
import chromeLocation from 'chrome-location2'
// Strict (Stable only)
console.log(chromeLocation())
// => "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" or null
// Enable fallback (Stable / Beta / Dev / Canary; includes Chromium on macOS/Windows; Chromium/Chromium-browser on Linux)
console.log(chromeLocation(true))
// => first found among Stable/Beta/Dev/Canary (or Chromium) or null
// Throw with an install guide when not found (path-only resolution; never executes the browser)
import {locateChromeOrExplain, getInstallGuidance, getChromeVersion} from 'chrome-location2'
try {
const path = locateChromeOrExplain({allowFallback: true})
console.log(path)
// Cross-platform version (no exec by default)
const v = getChromeVersion(path)
console.log(v) // e.g. "120.0.6099.109" or null
// Opt-in: allow executing the binary to fetch version on platforms without metadata (e.g. Linux)
const v2 = getChromeVersion(path, {allowExec: true})
console.log(v2)
} catch (e) {
console.error(String(e))
// Or print getInstallGuidance() explicitly
}CommonJS:
const api = require('chrome-location2')
const locateChrome = api.default || apiVia CLI:
npx chrome-location2
# Strict (Stable only)
npx chrome-location2 --fallback
# Enable cascade (Stable / Beta / Dev / Canary)
# Short flag
npx chrome-location2 -f
# Respect environment overrides
CHROME_FOR_TESTING_PATH=/custom/path/to/chrome npx chrome-location2
# Print Chrome version instead of path (no exec by default)
npx chrome-location2 --chrome-version
# Allow executing the binary if metadata is unavailable (mainly Linux)
npx chrome-location2 --chrome-version --allow-execExit behavior:
- Prints the resolved path on success
- Exits with code 1 and prints a guidance message if nothing suitable is found
- When
--chrome-versionis used: prints version or exits with code 2 if not determinable without exec and--allow-execwas not provided
Notes:
- Output is colorized when printed to a TTY (green success, red error)
- After you run
npx @puppeteer/browsers install chrome@stableonce, we auto-detect Chrome for Testing from Puppeteer's cache on all platforms. No env vars needed.
When nothing is found
When nothing is found, the helper throws with this message:
We couldn't find a Chrome/Chromium browser on this machine.
To install one:
1) Install Chrome for Testing (recommended)
npx @puppeteer/browsers install chrome@stable
Re-run your command afterward and it will be detected automatically.
Alternatively, install Chromium via your system's package manager and re-run.Support table
By default, only the Stable channel is checked. When fallback is enabled, Beta, Dev, and Canary (plus Chromium where applicable) are also checked (in that order) and the first existing path is returned.
Returns the first existing path found (given selected channels), or null if none are found.
API
default export locateChrome(allowFallback?: boolean): string | null- Returns the first existing path among the selected channels or
null. - When
allowFallbackistrue, checks Stable → Beta → Dev → Canary. May also consider Chromium depending on platform.
- Returns the first existing path among the selected channels or
locateChromeOrExplain(options?: boolean | { allowFallback?: boolean }): string- Returns a path if found, otherwise throws an
Errorwith a friendly installation guide. - Path resolution never executes the browser.
- Returns a path if found, otherwise throws an
getChromeVersion(bin: string, opts?: { allowExec?: boolean }): string | null- Cross-platform version resolver that does not execute the browser by default.
- Windows: reads PE file metadata via PowerShell (no GUI spawn).
- macOS: reads
Info.plist(no GUI spawn). - Linux/other: attempts to infer from Puppeteer cache path; if not available, returns
nullunlessallowExecistrue.
getInstallGuidance(): string- Returns the same guidance text used by
locateChromeOrExplain().
- Returns the same guidance text used by
Environment overrides
If any of these environment variables are set and point to an existing binary, they take precedence:
CHROME_FOR_TESTING_PATHCHROMIUM_BINARYCHROME_BINARY
Related projects
- brave-location
- chromium-location
- edge-location
- firefox-location2
- safari-location2
- opera-location2
- vivaldi-location2
- waterfox-location
- librewolf-location
- yandex-location
License
MIT (c) Cezar Augusto.
