safari-location2
v2.1.0
Published
Approximates the current location of the Safari browser across platforms.
Downloads
286
Maintainers
Readme
Approximates the current location of the Safari browser across platforms.
safari-location2

- By default checks only
stable. Optionally can cascade toTechnology Preview. - Supports macOS
- Works both as an ES module or CommonJS
Installation
npm i safari-location2Support table
This table lists the default locations where Safari 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.
Usage
Via Node.js (strict by default):
import safariLocation from 'safari-location2'
import {
locateSafariOrExplain,
getInstallGuidance,
getSafariVersion
} from 'safari-location2'
// Strict (Stable only)
console.log(safariLocation())
// => "/Applications/Safari.app/Contents/MacOS/Safari" or null
// Enable fallback (Stable / Technology Preview)
console.log(safariLocation(true))
// => first found among Stable/Technology Preview or null
// Throw with an install guide when not found
try {
const bin = locateSafariOrExplain({allowFallback: true})
console.log(bin)
// Version (no exec by default)
console.log(getSafariVersion(bin)) // e.g. "17.6" or null
} catch (e) {
console.error(String(e))
// Or print getInstallGuidance() explicitly
}CommonJS:
const api = require('safari-location2')
const locateSafari = api.default || apiVia CLI:
npx safari-location2
# Strict (Stable only)
npx safari-location2 --fallback
# Enable cascade (Stable / Technology Preview)
# Respect environment overrides
SAFARI_BINARY=/custom/path/to/Safari npx safari-location2
# Print browser version (empty + exit code 2 if unavailable)
npx safari-location2 --safari-version
npx safari-location2 --browser-version
# Opt-in: allow executing the binary to fetch version
npx safari-location2 --browser-version --allow-execEnvironment overrides
If this environment variable is set and points to an existing binary, it takes precedence:
SAFARI_BINARY
API
default export locateSafari(allowFallback?: boolean): string | nulllocateSafariOrExplain(options?: boolean | { allowFallback?: boolean }): stringgetSafariVersion(bin: string, opts?: { allowExec?: boolean }): string | nullgetInstallGuidance(): stringdetectSafariToolchain(deps?: ToolchainDeps): SafariToolchainisMacOS(platform?: NodeJS.Platform): boolean
Toolchain detection
Building Safari web extensions requires more than the browser itself:
safari-web-extension-converter and xcodebuild ship with full Xcode
(the Command Line Tools alone are not enough). detectSafariToolchain()
reports what is available:
import { detectSafariToolchain } from 'safari-location2'
const toolchain = detectSafariToolchain()
// {
// platformOk: true, // running on macOS
// developerDir: '/Applications/Xcode.app/Contents/Developer',
// needsFullXcode: false, // true when only Command Line Tools are active
// converter: '/usr/bin/safari-web-extension-converter',
// xcodebuild: '/usr/bin/xcodebuild',
// ok: true // converter + xcodebuild both resolved
// }Related projects
- brave-location
- chrome-location2
- chromium-location
- edge-location
- firefox-location2
- opera-location2
- vivaldi-location2
- waterfox-location
- librewolf-location
- yandex-location
License
MIT (c) Cezar Augusto.
