Last active
May 30, 2023 08:36
-
-
Save kingbotss/6f959fb69a9c050c10ca30f3242d5d13 to your computer and use it in GitHub Desktop.
Node js script to get chrome, edge, brave browser location on windows
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
| const fs=require('fs'); | |
| function getChromeExe(chromeDirName) { | |
| if (process.platform !== 'win32') { | |
| return null; | |
| } | |
| var windowsChromeDirectory, i, prefix; | |
| var suffix = '\\Google\\'+ chromeDirName + '\\Application\\chrome.exe'; | |
| var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']]; | |
| for (i = 0; i < prefixes.length; i++) { | |
| prefix = prefixes[i]; | |
| if (fs.existsSync(prefix + suffix)) { | |
| windowsChromeDirectory = prefix + suffix; | |
| break; | |
| } | |
| } | |
| return windowsChromeDirectory; | |
| } | |
| function getEdgeExe(chromeDirName) { | |
| if (process.platform !== 'win32') { | |
| return null; | |
| } | |
| var windowsChromeDirectory, i, prefix; | |
| var suffix = '\\Microsoft\\'+ chromeDirName + '\\Application\\msedge.exe'; | |
| var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']]; | |
| for (i = 0; i < prefixes.length; i++) { | |
| prefix = prefixes[i]; | |
| if (fs.existsSync(prefix + suffix)) { | |
| windowsChromeDirectory = prefix + suffix; | |
| break; | |
| } | |
| } | |
| return windowsChromeDirectory; | |
| } | |
| function getBraveExe(chromeDirName) { | |
| if (process.platform !== 'win32') { | |
| return null; | |
| } | |
| var windowsChromeDirectory, i, prefix; | |
| var suffix = '\\BraveSoftware\\'+ chromeDirName + '-Browser\\Application\\brave.exe'; | |
| var prefixes = [process.env.LOCALAPPDATA, process.env.PROGRAMFILES, process.env['PROGRAMFILES(X86)']]; | |
| for (i = 0; i < prefixes.length; i++) { | |
| prefix = prefixes[i]; | |
| if (fs.existsSync(prefix + suffix)) { | |
| windowsChromeDirectory = prefix + suffix; | |
| break; | |
| } | |
| } | |
| return windowsChromeDirectory; | |
| } | |
| module.exports={chrome:getChromeExe,edge:getEdgeExe,brave:getBraveExe} |
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
| const browsers=require('./browser'); | |
| //get chrome/microsoft Edge/Brave browser locations on windows | |
| browsers['brave']('Brave') | |
| browsers['chrome']('Chrome') | |
| browsers['edge']('Edge') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment