fix(browser): preserve wss:// cdpUrl in legacy default profile resolution
This commit is contained in:
parent
7fce53976e
commit
e2ecd0a321
@ -165,6 +165,17 @@ describe("browser config", () => {
|
|||||||
expect(work?.cdpUrl).toBe("https://example.com:18801");
|
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", () => {
|
it("rejects unsupported protocols", () => {
|
||||||
expect(() => resolveBrowserConfig({ cdpUrl: "ftp://127.0.0.1:18791" })).toThrow(
|
expect(() => resolveBrowserConfig({ cdpUrl: "ftp://127.0.0.1:18791" })).toThrow(
|
||||||
"must be http(s) or ws(s)",
|
"must be http(s) or ws(s)",
|
||||||
|
|||||||
@ -162,12 +162,17 @@ function ensureDefaultProfile(
|
|||||||
defaultColor: string,
|
defaultColor: string,
|
||||||
legacyCdpPort?: number,
|
legacyCdpPort?: number,
|
||||||
derivedDefaultCdpPort?: number,
|
derivedDefaultCdpPort?: number,
|
||||||
|
legacyCdpUrl?: string,
|
||||||
): Record<string, BrowserProfileConfig> {
|
): Record<string, BrowserProfileConfig> {
|
||||||
const result = { ...profiles };
|
const result = { ...profiles };
|
||||||
if (!result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME]) {
|
if (!result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME]) {
|
||||||
result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME] = {
|
result[DEFAULT_OPENCLAW_BROWSER_PROFILE_NAME] = {
|
||||||
cdpPort: legacyCdpPort ?? derivedDefaultCdpPort ?? CDP_PORT_RANGE_START,
|
cdpPort: legacyCdpPort ?? derivedDefaultCdpPort ?? CDP_PORT_RANGE_START,
|
||||||
color: defaultColor,
|
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;
|
return result;
|
||||||
@ -260,8 +265,11 @@ export function resolveBrowserConfig(
|
|||||||
const defaultProfileFromConfig = cfg?.defaultProfile?.trim() || undefined;
|
const defaultProfileFromConfig = cfg?.defaultProfile?.trim() || undefined;
|
||||||
// Use legacy cdpUrl port for backward compatibility when no profiles configured
|
// Use legacy cdpUrl port for backward compatibility when no profiles configured
|
||||||
const legacyCdpPort = rawCdpUrl ? cdpInfo.port : undefined;
|
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(
|
const profiles = ensureDefaultChromeExtensionProfile(
|
||||||
ensureDefaultProfile(cfg?.profiles, defaultColor, legacyCdpPort, cdpPortRangeStart),
|
ensureDefaultProfile(cfg?.profiles, defaultColor, legacyCdpPort, cdpPortRangeStart, legacyCdpUrl),
|
||||||
controlPort,
|
controlPort,
|
||||||
);
|
);
|
||||||
const cdpProtocol = cdpInfo.parsed.protocol === "https:" ? "https" : "http";
|
const cdpProtocol = cdpInfo.parsed.protocol === "https:" ? "https" : "http";
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user