Normalize basePath before building default WebSocket URL

When window.__OPENCLAW_CONTROL_UI_BASE_PATH__ is set, normalize it via
normalizeBasePath() before concatenation — matching what inferBasePath()
in app-settings.ts already does. Without this, values like "openclaw"
(no leading slash) or "/openclaw/" (trailing slash) produce malformed
WebSocket URLs on first load.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ben Gitter
2026-03-01 02:28:00 +00:00
committed by Radek Sienkiewicz
parent 3ed11f9651
commit 413d41a79a

View File

@@ -1,7 +1,7 @@
const KEY = "openclaw.control.settings.v1";
import { isSupportedLocale } from "../i18n/index.ts";
import { inferBasePathFromPathname } from "./navigation.ts";
import { inferBasePathFromPathname, normalizeBasePath } from "./navigation.ts";
import type { ThemeMode } from "./theme.ts";
export type UiSettings = {
@@ -21,9 +21,13 @@ export type UiSettings = {
export function loadSettings(): UiSettings {
const defaultUrl = (() => {
const proto = location.protocol === "https:" ? "wss" : "ws";
const basePath =
(typeof window !== "undefined" && window.__OPENCLAW_CONTROL_UI_BASE_PATH__) ||
inferBasePathFromPathname(location.pathname);
const configured =
typeof window !== "undefined" &&
typeof window.__OPENCLAW_CONTROL_UI_BASE_PATH__ === "string" &&
window.__OPENCLAW_CONTROL_UI_BASE_PATH__.trim();
const basePath = configured
? normalizeBasePath(configured)
: inferBasePathFromPathname(location.pathname);
return `${proto}://${location.host}${basePath}`;
})();