firefox-location2
v2.1.1
Published
Approximates the current location of the Firefox browser across platforms.
Maintainers
Readme
Approximates the current location of the Firefox browser across platforms.
firefox-location2

- By default checks only
stable. Optionally can cascade toesr/developer edition/nightly. - Supports macOS / Windows / Linux
- Works both as an ES module or CommonJS
New in this version:
- Optional helper to throw with a friendly install guide when nothing is found
- CLI output is colorized (green on success, red on error)
- After you run
npx @puppeteer/browsers install firefox@stableonce, we auto-detect Firefox from Puppeteer's cache on all platforms (no env vars needed)
Support table
This table lists the default locations where Firefox is typically installed for each supported platform and channel. By default, only the Stable channel is checked. When fallback is enabled, the package checks these paths (in order) and returns the first one found.
Returns the first existing path found (given selected channels), or null if none are found.
Note: On Linux, the module first tries to resolve binaries on $PATH (using which) for the common channels listed above, then falls back to checking common filesystem locations like /usr/bin/firefox, /usr/local/bin/firefox, /snap/bin/firefox, and /opt/firefox/firefox.
Usage
Via Node.js (strict by default):
import firefoxLocation from 'firefox-location2'
import {getFirefoxVersion} from 'firefox-location2'
// Strict (Stable only)
console.log(firefoxLocation())
// => "/Applications/Firefox.app/Contents/MacOS/firefox" or null
// Enable fallback (Stable / ESR / Developer Edition / Nightly)
console.log(firefoxLocation(true))
// => first found among Stable/ESR/Developer/Nightly or null
// Throw with a friendly, copy-pasteable guide when not found
import {locateFirefoxOrExplain, getInstallGuidance} from 'firefox-location2'
try {
const path = locateFirefoxOrExplain({allowFallback: true})
console.log(path)
// Cross-platform version (no exec by default)
const v = getFirefoxVersion(path)
console.log(v) // e.g. "130.0.1" or null
// Opt-in: allow executing the binary to fetch version on platforms without metadata (e.g. Linux)
const v2 = getFirefoxVersion(path, {allowExec: true})
console.log(v2)
} catch (e) {
console.error(String(e))
// Or print getInstallGuidance() explicitly
}CommonJS:
const api = require('firefox-location2')
const locateFirefox = api.default || api
// Strict (Stable only)
console.log(locateFirefox())
// With fallback enabled
console.log(locateFirefox(true))
// Helper that throws with guidance
try {
const p = (
api.locateFirefoxOrExplain || ((o) => locateFirefox(o?.allowFallback))
)({allowFallback: true})
console.log(p)
} catch (e) {
console.error(String(e))
}Via CLI:
npx firefox-location2
# Strict (Stable only)
npx firefox-location2 --fallback
# Enable cascade (Stable / ESR / Developer / Nightly)
# Output is colorized when printed to a TTY
# Respect Puppeteer cache (after you install once):
npx @puppeteer/browsers install firefox@stable
npx firefox-location2Environment overrides
If this environment variable is set and points to an existing binary, it takes precedence:
FIREFOX_BINARY
Exit behavior:
- Prints the resolved path on success
- Exits with code 1 and prints a guidance message if nothing suitable is found
Notes:
- Output is colorized when printed to a TTY (green success, red error)
- After you run
npx @puppeteer/browsers install firefox@stableonce, we auto-detect Firefox from Puppeteer's cache on all platforms. No env vars needed.
API
default export locateFirefox(allowFallback?: boolean): string | null- Returns the first existing path among the selected channels or
null. - When
allowFallbackistrue, checks Stable → ESR → Developer → Nightly.
- Returns the first existing path among the selected channels or
locateFirefoxOrExplain(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
getFirefoxVersion(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: returns
nullunlessallowExecistrue, then tries--version.
Planned enhancements
- Flatpak detection on Linux: detect installed Flatpak app org.mozilla.firefox and expose the appropriate invocation.
- Custom build locations: probe common custom paths such as ~/bin/firefox, ~/Downloads/firefox/firefox, /usr/local/firefox/firefox, /opt/firefox-dev/firefox.
- Optional binary validation: helper to return firefox --version (or Flatpak equivalent) for diagnostics.
- Optional launch helpers: generate safe args (e.g., --no-remote, --new-instance, -profile, optional -start-debugger-server), with Flatpak-specific sandbox flags when applicable.
Related projects
License
MIT (c) Cezar Augusto.
