Created
October 25, 2015 03:18
-
-
Save chrisl8888/4e4cc3001b4423db546b to your computer and use it in GitHub Desktop.
get chrome location with nodejs - from chrome-location: https://github.com/hughsk/chrome-location/blob/master/index.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var osx = process.platform === 'darwin' | |
| var win = process.platform === 'win32' | |
| var other = !osx && !win | |
| var fs = require('fs') | |
| if (other) { | |
| try { | |
| module.exports = require('which').sync('google-chrome') | |
| } catch(e) { | |
| module.exports = null | |
| } | |
| } else | |
| if (osx) { | |
| var regPath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome' | |
| var altPath = require('userhome')(regPath.slice(1)) | |
| module.exports = fs.existsSync(regPath) | |
| ? regPath | |
| : altPath | |
| } else { | |
| var suffix = '\\Google\\Chrome\\Application\\chrome.exe'; | |
| var prefixes = [ | |
| process.env.LOCALAPPDATA | |
| , process.env.PROGRAMFILES | |
| , process.env['PROGRAMFILES(X86)'] | |
| ] | |
| for (var i = 0; i < prefixes.length; i++) { | |
| var exe = prefixes[i] + suffix | |
| if (fs.existsSync(exe)) { | |
| module.exports = exe | |
| break | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment