From 9ebd99745e9a100945f0608ab9760a358fab2453 Mon Sep 17 00:00:00 2001 From: Joe Doyle Date: Tue, 13 Aug 2013 09:57:00 -0400 Subject: [PATCH] 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 --- index.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 9edb727..696459f 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,6 @@ +var os = require('os'), + fs = require('fs'); + var ChromeBrowser = function(baseBrowserDecorator, args) { baseBrowserDecorator(this); @@ -22,7 +25,7 @@ ChromeBrowser.prototype = { DEFAULT_CMD: { linux: 'google-chrome', darwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', - win32: process.env.LOCALAPPDATA + '\\Google\\Chrome\\Application\\chrome.exe' + win32: windowsChromePath('\\Google\\Chrome\\Application\\chrome.exe') }, ENV_CMD: 'CHROME_BIN' }; @@ -46,13 +49,26 @@ ChromeCanaryBrowser.prototype = { DEFAULT_CMD: { linux: 'google-chrome-canary', darwin: '/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary', - win32: process.env.LOCALAPPDATA + '\\Google\\Chrome SxS\\Application\\chrome.exe' + win32: windowsChromePath('\\Google\\Chrome SxS\\Application\\chrome.exe') }, ENV_CMD: 'CHROME_CANARY_BIN' }; ChromeCanaryBrowser.$inject = ['baseBrowserDecorator', 'args']; +var windowsChromePath = function(chromeExe) { + if (os.platform() !== 'win32') { + return ''; + } + + var globalInstall = os.arch() === 'x64' ? process.env['ProgramFiles(x86)'] : process.env.ProgramFiles; + + if (fs.existsSync(globalInstall + chromeExe)) { + return globalInstall + chromeExe; + } + + return process.env.LOCALAPPDATA + chromeExe; +} // PUBLISH DI MODULE module.exports = {