Skip to content

Commit 9ebd997

Browse files
Joe Doylevojtajina
authored andcommitted
fix: correct Chrome path on Windows
Checks for Chrome in the default location on windows taking into account 32 and 64 bit machines. Falls back to the version in the user's profile. Closes #2
1 parent ee0958e commit 9ebd997

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

index.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
var os = require('os'),
2+
fs = require('fs');
3+
14
var ChromeBrowser = function(baseBrowserDecorator, args) {
25
baseBrowserDecorator(this);
36

@@ -22,7 +25,7 @@ ChromeBrowser.prototype = {
2225
DEFAULT_CMD: {
2326
linux: 'google-chrome',
2427
darwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
25-
win32: process.env.LOCALAPPDATA + '\\Google\\Chrome\\Application\\chrome.exe'
28+
win32: windowsChromePath('\\Google\\Chrome\\Application\\chrome.exe')
2629
},
2730
ENV_CMD: 'CHROME_BIN'
2831
};
@@ -46,13 +49,26 @@ ChromeCanaryBrowser.prototype = {
4649
DEFAULT_CMD: {
4750
linux: 'google-chrome-canary',
4851
darwin: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
49-
win32: process.env.LOCALAPPDATA + '\\Google\\Chrome SxS\\Application\\chrome.exe'
52+
win32: windowsChromePath('\\Google\\Chrome SxS\\Application\\chrome.exe')
5053
},
5154
ENV_CMD: 'CHROME_CANARY_BIN'
5255
};
5356

5457
ChromeCanaryBrowser.$inject = ['baseBrowserDecorator', 'args'];
5558

59+
var windowsChromePath = function(chromeExe) {
60+
if (os.platform() !== 'win32') {
61+
return '';
62+
}
63+
64+
var globalInstall = os.arch() === 'x64' ? process.env['ProgramFiles(x86)'] : process.env.ProgramFiles;
65+
66+
if (fs.existsSync(globalInstall + chromeExe)) {
67+
return globalInstall + chromeExe;
68+
}
69+
70+
return process.env.LOCALAPPDATA + chromeExe;
71+
}
5672

5773
// PUBLISH DI MODULE
5874
module.exports = {

0 commit comments

Comments
 (0)