mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:30:45 +00:00
fix: expand browser executable home paths
This commit is contained in:
@@ -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: {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user