mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-15 12:00:43 +00:00
fix(browser): preserve wss:// cdpUrl in legacy default profile resolution
This commit is contained in:
committed by
Peter Steinberger
parent
7fce53976e
commit
e2ecd0a321
@@ -165,6 +165,17 @@ describe("browser config", () => {
|
||||
expect(work?.cdpUrl).toBe("https://example.com:18801");
|
||||
});
|
||||
|
||||
it("preserves wss:// cdpUrl with query params for the default profile", () => {
|
||||
const resolved = resolveBrowserConfig({
|
||||
cdpUrl: "wss://connect.browserbase.com?apiKey=test-key",
|
||||
});
|
||||
const profile = resolveProfile(resolved, "openclaw");
|
||||
expect(profile?.cdpUrl).toBe("wss://connect.browserbase.com/?apiKey=test-key");
|
||||
expect(profile?.cdpHost).toBe("connect.browserbase.com");
|
||||
expect(profile?.cdpPort).toBe(443);
|
||||
expect(profile?.cdpIsLoopback).toBe(false);
|
||||
});
|
||||
|
||||
it("rejects unsupported protocols", () => {
|
||||
expect(() => resolveBrowserConfig({ cdpUrl: "ftp://127.0.0.1:18791" })).toThrow(
|
||||
"must be http(s) or ws(s)",
|
||||
|
||||
@@ -162,12 +162,17 @@ function ensureDefaultProfile(
|
||||
defaultColor: string,
|
||||
legacyCdpPort?: number,
|
||||
derivedDefaultCdpPort?: number,
|
||||
legacyCdpUrl?: string,
|
||||
): Record<string, BrowserProfileConfig> {
|
||||
const result = { ...profiles };
|
||||
if (!result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME]) {
|
||||
result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME] = {
|
||||
cdpPort: legacyCdpPort ?? derivedDefaultCdpPort ?? CDP_PORT_RANGE_START,
|
||||
color: defaultColor,
|
||||
// Preserve the full cdpUrl for ws/wss endpoints so resolveProfile()
|
||||
// doesn't reconstruct from cdpProtocol/cdpHost/cdpPort (which drops
|
||||
// the WebSocket protocol and query params like API keys).
|
||||
...(legacyCdpUrl ? { cdpUrl: legacyCdpUrl } : {}),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
@@ -260,8 +265,11 @@ export function resolveBrowserConfig(
|
||||
const defaultProfileFromConfig = cfg?.defaultProfile?.trim() || undefined;
|
||||
// Use legacy cdpUrl port for backward compatibility when no profiles configured
|
||||
const legacyCdpPort = rawCdpUrl ? cdpInfo.port : undefined;
|
||||
const isWsUrl =
|
||||
cdpInfo.parsed.protocol === "ws:" || cdpInfo.parsed.protocol === "wss:";
|
||||
const legacyCdpUrl = rawCdpUrl && isWsUrl ? cdpInfo.normalized : undefined;
|
||||
const profiles = ensureDefaultChromeExtensionProfile(
|
||||
ensureDefaultProfile(cfg?.profiles, defaultColor, legacyCdpPort, cdpPortRangeStart),
|
||||
ensureDefaultProfile(cfg?.profiles, defaultColor, legacyCdpPort, cdpPortRangeStart, legacyCdpUrl),
|
||||
controlPort,
|
||||
);
|
||||
const cdpProtocol = cdpInfo.parsed.protocol === "https:" ? "https" : "http";
|
||||
|
||||
Reference in New Issue
Block a user