fix(browser): support Windows Chrome detection (PR #439, thanks @mrdbstn)

This commit is contained in:
Peter Steinberger
2026-01-08 02:08:59 +00:00
parent 7294ba037d
commit 1e826862c3
3 changed files with 41 additions and 35 deletions

View File

@@ -136,6 +136,7 @@ describe("browser chrome profile decoration", () => {
describe("browser chrome helpers", () => {
afterEach(() => {
vi.unstubAllEnvs();
vi.unstubAllGlobals();
vi.restoreAllMocks();
});
@@ -157,6 +158,7 @@ describe("browser chrome helpers", () => {
});
it("picks the first existing Chrome candidate on Windows", () => {
vi.stubEnv("LOCALAPPDATA", "C:\\Users\\Test\\AppData\\Local");
const exists = vi
.spyOn(fs, "existsSync")
.mockImplementation((p) => String(p).includes("Chrome SxS"));
@@ -167,8 +169,7 @@ describe("browser chrome helpers", () => {
});
it("finds Chrome in Program Files on Windows", () => {
// Use path.join to match how the function builds paths (cross-platform)
const marker = path.join("Program Files", "Google", "Chrome");
const marker = path.win32.join("Program Files", "Google", "Chrome");
const exists = vi
.spyOn(fs, "existsSync")
.mockImplementation((p) => String(p).includes(marker));

View File

@@ -109,57 +109,61 @@ export function findChromeExecutableWindows(): BrowserExecutable | null {
const programFilesX86 =
process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
const candidates: Array<BrowserExecutable> = [
const joinWin = path.win32.join;
const candidates: Array<BrowserExecutable> = [];
if (localAppData) {
// Chrome Canary (user install)
{
candidates.push({
kind: "canary",
path: path.join(
path: joinWin(
localAppData,
"Google",
"Chrome SxS",
"Application",
"chrome.exe",
),
},
});
// Chromium (user install)
{
candidates.push({
kind: "chromium",
path: path.join(localAppData, "Chromium", "Application", "chrome.exe"),
},
path: joinWin(localAppData, "Chromium", "Application", "chrome.exe"),
});
// Chrome (user install)
{
candidates.push({
kind: "chrome",
path: path.join(
path: joinWin(
localAppData,
"Google",
"Chrome",
"Application",
"chrome.exe",
),
},
// Chrome (system install, 64-bit)
{
kind: "chrome",
path: path.join(
programFiles,
"Google",
"Chrome",
"Application",
"chrome.exe",
),
},
// Chrome (system install, 32-bit on 64-bit Windows)
{
kind: "chrome",
path: path.join(
programFilesX86,
"Google",
"Chrome",
"Application",
"chrome.exe",
),
},
];
});
}
// Chrome (system install, 64-bit)
candidates.push({
kind: "chrome",
path: joinWin(
programFiles,
"Google",
"Chrome",
"Application",
"chrome.exe",
),
});
// Chrome (system install, 32-bit on 64-bit Windows)
candidates.push({
kind: "chrome",
path: joinWin(
programFilesX86,
"Google",
"Chrome",
"Application",
"chrome.exe",
),
});
for (const candidate of candidates) {
if (exists(candidate.path)) return candidate;