UNPKG

chrome-location2

Version:

Approximates the current location of the Chrome browser across platforms.

53 lines (52 loc) 1.9 kB
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs"; import * as __WEBPACK_EXTERNAL_MODULE_userhome__ from "userhome"; import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path"; import * as __WEBPACK_EXTERNAL_MODULE_which__ from "which"; function scanOsxPath() { const defaultPath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; const alternativePath = (0, __WEBPACK_EXTERNAL_MODULE_userhome__["default"])(defaultPath.slice(1)); if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(defaultPath)) return defaultPath; return alternativePath; } function scanWindowsPath() { let browserPath = null; const prefixes = [ process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)'] ]; const suffix = '\\Google\\Chrome\\Application\\chrome.exe'; for (const prefix of prefixes){ if (!prefix) continue; const exe = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(prefix, suffix); if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(exe)) { browserPath = exe; break; } } return browserPath; } function scanUnknownPlatform() { let browserPath = null; try { browserPath = __WEBPACK_EXTERNAL_MODULE_which__["default"].sync('google-chrome'); } catch (err) { try { browserPath = __WEBPACK_EXTERNAL_MODULE_which__["default"].sync('chromium-browser'); } catch (err) { browserPath = null; } } return browserPath; } function locateChrome() { switch(process.platform){ case 'darwin': return scanOsxPath(); case 'win32': return scanWindowsPath(); default: return scanUnknownPlatform(); } } export { locateChrome as default };