Skip to content

Commit

Permalink
fix: Make Windows browser version queries more robust
Browse files Browse the repository at this point in the history
This fixes missing chromedriver in GitHub Actions on Windows.

Instead of querying an arcane registry key to find the installed version
of a browser, query a _different_ arcane registry key to get the path to
the browser executable, then query the version of the executable using
powershell.
  • Loading branch information
joeyparrish committed Feb 3, 2022
1 parent 8c377b6 commit 85f3b27
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
4 changes: 1 addition & 3 deletions chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class ChromeWebDriverInstaller extends WebDriverInstallerBase {
} else if (os.platform() == 'darwin') {
return await InstallerUtils.getMacAppVersion('Google Chrome');
} else if (os.platform() == 'win32') {
return await InstallerUtils.getWindowsRegistryVersion(
'HKCU\\Software\\Google\\Chrome\\BLBeacon',
'version');
return await InstallerUtils.getWindowsExeVersion('chrome.exe');
} else {
throw new Error(`Unrecognized platform: ${os.platform()}`);
}
Expand Down
3 changes: 1 addition & 2 deletions edge.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class EdgeWebDriverInstaller extends WebDriverInstallerBase {
} else if (os.platform() == 'darwin') {
return await InstallerUtils.getMacAppVersion('Microsoft Edge');
} else if (os.platform() == 'win32') {
return await InstallerUtils.getWindowsExeVersion(
'C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe');
return await InstallerUtils.getWindowsExeVersion('msedge.exe');
} else {
throw new Error(`Unrecognized platform: ${os.platform()}`);
}
Expand Down
4 changes: 1 addition & 3 deletions firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class FirefoxWebDriverInstaller extends WebDriverInstallerBase {
} else if (os.platform() == 'darwin') {
return await InstallerUtils.getMacAppVersion('Firefox');
} else if (os.platform() == 'win32') {
return await InstallerUtils.getWindowsRegistryVersion(
'HKLM\\Software\\Mozilla\\Mozilla Firefox',
'CurrentVersion')
return await InstallerUtils.getWindowsExeVersion('firefox.exe');
} else {
throw new Error(`Unrecognized platform: ${os.platform()}`);
}
Expand Down
23 changes: 19 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const execFile = util.promisify(childProcess.execFile);
const pipeline = util.promisify(stream.pipeline);
const zipFromBuffer = util.promisify(yauzl.fromBuffer);

const WINDOWS_REGISTRY_APP_PATHS =
'HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\App\ Paths\\';

/**
* A static utility class for driver installers to use for common operations.
*/
Expand Down Expand Up @@ -90,7 +93,12 @@ class InstallerUtils {
return null;
}

const result = await regQuery(path, '64');
// Try the 64-bit registry first, then fall back to the 32-bit registry.
// Necessary values could be in either location.
let result = await regQuery(path, '64');
if (!result[path].exists || !result[path].values[key]) {
result = await regQuery(path, '32');
}
if (!result[path].exists || !result[path].values[key]) {
return null;
}
Expand Down Expand Up @@ -125,9 +133,16 @@ class InstallerUtils {
}

if (!(await InstallerUtils.fileExists(path))) {
// No such file. Avoid the need to parse "not found" errors from
// powershell output.
return null;
// No such file.
// If it's a relative path, ask the registry for a full one.
if (!path.includes('/') && !path.includes('\\')) {
path = await InstallerUtils.getWindowsRegistryVersion(
WINDOWS_REGISTRY_APP_PATHS + path,
'');
if (!path || !(await InstallerUtils.fileExists(path))) {
return null;
}
}
}

const result = await InstallerUtils.runCommand([
Expand Down

0 comments on commit 85f3b27

Please sign in to comment.