fix: expand browser executable home paths

This commit is contained in:
Peter Steinberger
2026-04-25 03:15:50 +01:00
parent 4a7ddd7ff5
commit 95a2c9bcdc
5 changed files with 43 additions and 2 deletions

View File

@@ -1,3 +1,5 @@
import os from "node:os";
import path from "node:path";
import { describe, expect, it } from "vitest";
import type { BrowserConfig } from "../config/config.js";
import { resolveUserPath } from "../utils.js";
@@ -139,6 +141,30 @@ describe("browser config", () => {
});
});
it("expands tilde-prefixed executablePath with the OS home directory", () => {
const resolved = resolveBrowserConfig({
executablePath: " ~/.local/bin/chromium ",
});
expect(resolved.executablePath).toBe(path.resolve(os.homedir(), ".local/bin/chromium"));
});
it("keeps non-tilde executablePath values unchanged after trimming", () => {
const resolved = resolveBrowserConfig({
executablePath: " ./local-chromium ",
});
expect(resolved.executablePath).toBe("./local-chromium");
});
it("normalizes blank executablePath to undefined", () => {
const resolved = resolveBrowserConfig({
executablePath: " ",
});
expect(resolved.executablePath).toBeUndefined();
});
it("normalizes invalid browser tab cleanup numbers to defaults", () => {
const resolved = resolveBrowserConfig({
tabCleanup: {

View File

@@ -1,3 +1,5 @@
import os from "node:os";
import path from "node:path";
import {
normalizeOptionalString,
normalizeOptionalTrimmedStringList,
@@ -125,6 +127,17 @@ function normalizePositiveInteger(raw: number | undefined, fallback: number): nu
return value <= 0 ? fallback : value;
}
function normalizeExecutablePath(raw: string | undefined): string | undefined {
const value = normalizeOptionalString(raw);
if (!value) {
return undefined;
}
if (!/^~(?=$|[\\/])/.test(value)) {
return value;
}
return path.resolve(value.replace(/^~(?=$|[\\/])/, os.homedir()));
}
function resolveBrowserTabCleanupConfig(
cfg: BrowserConfig | undefined,
): ResolvedBrowserTabCleanupConfig {
@@ -287,7 +300,7 @@ export function resolveBrowserConfig(
const headless = cfg?.headless === true;
const noSandbox = cfg?.noSandbox === true;
const attachOnly = cfg?.attachOnly === true;
const executablePath = normalizeOptionalString(cfg?.executablePath);
const executablePath = normalizeExecutablePath(cfg?.executablePath);
const defaultProfileFromConfig = normalizeOptionalString(cfg?.defaultProfile);
const legacyCdpPort = rawCdpUrl ? cdpInfo.port : undefined;