Merge 58a8b9c4565ed2ce0ff1e5700c20ac9ba558c94a into 598f1826d8b2bc969aace2c6459824737667218c

This commit is contained in:
kaiwangleo 2026-03-21 03:51:01 +00:00 committed by GitHub
commit 6fe8bd5646
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 2 deletions

View File

@ -58,6 +58,19 @@ describe("browser config", () => {
});
});
it("keeps local browser relay defaults when gateway.mode=remote", () => {
withEnv({ OPENCLAW_GATEWAY_PORT: undefined }, () => {
const resolved = resolveBrowserConfig(undefined, {
gateway: { mode: "remote", port: 443 },
});
expect(resolved.controlPort).toBe(18791);
const chrome = resolveProfile(resolved, "chrome");
expect(chrome?.driver).toBe("extension");
expect(chrome?.cdpPort).toBe(18792);
expect(chrome?.cdpUrl).toBe("http://127.0.0.1:18792");
});
});
it("supports overriding the local CDP auto-allocation range start", () => {
const resolved = resolveBrowserConfig({
cdpPortRangeStart: 19000,

View File

@ -1,5 +1,5 @@
import type { BrowserConfig, BrowserProfileConfig, OpenClawConfig } from "../config/config.js";
import { resolveGatewayPort } from "../config/paths.js";
import { DEFAULT_GATEWAY_PORT, resolveGatewayPort } from "../config/paths.js";
import {
deriveDefaultBrowserCdpPortRange,
deriveDefaultBrowserControlPort,
@ -205,7 +205,17 @@ export function resolveBrowserConfig(
const enabled = cfg?.enabled ?? DEFAULT_OPENCLAW_BROWSER_ENABLED;
const evaluateEnabled = cfg?.evaluateEnabled ?? DEFAULT_BROWSER_EVALUATE_ENABLED;
const gatewayPort = resolveGatewayPort(rootConfig);
const controlPort = deriveDefaultBrowserControlPort(gatewayPort ?? DEFAULT_BROWSER_CONTROL_PORT);
// In gateway.mode=remote, gateway.port often points to a remote ingress port (e.g. 443).
// Browser relay/control ports remain local on the current host, so derive defaults from
// the local gateway default unless browser ports are explicitly configured.
const gatewayMode =
typeof rootConfig?.gateway?.mode === "string"
? rootConfig.gateway.mode.trim().toLowerCase()
: undefined;
const browserPortBase = gatewayMode === "remote" ? DEFAULT_GATEWAY_PORT : gatewayPort;
const controlPort = deriveDefaultBrowserControlPort(
browserPortBase ?? DEFAULT_BROWSER_CONTROL_PORT,
);
const defaultColor = normalizeHexColor(cfg?.color);
const remoteCdpTimeoutMs = normalizeTimeoutMs(cfg?.remoteCdpTimeoutMs, 1500);
const remoteCdpHandshakeTimeoutMs = normalizeTimeoutMs(