mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 02:38:26 +00:00
fix: make browser relay bind address configurable (#39364) (thanks @mvanhorn)
This commit is contained in:
@@ -1202,4 +1202,23 @@ describe("chrome extension relay server", () => {
|
||||
},
|
||||
RELAY_TEST_TIMEOUT_MS,
|
||||
);
|
||||
|
||||
it(
|
||||
"restarts the relay when bindHost changes for the same port",
|
||||
async () => {
|
||||
const port = await getFreePort();
|
||||
cdpUrl = `http://127.0.0.1:${port}`;
|
||||
|
||||
const initial = await ensureChromeExtensionRelayServer({ cdpUrl });
|
||||
expect(initial.bindHost).toBe("127.0.0.1");
|
||||
|
||||
const rebound = await ensureChromeExtensionRelayServer({
|
||||
cdpUrl,
|
||||
bindHost: "0.0.0.0",
|
||||
});
|
||||
expect(rebound.bindHost).toBe("0.0.0.0");
|
||||
expect(rebound.port).toBe(port);
|
||||
},
|
||||
RELAY_TEST_TIMEOUT_MS,
|
||||
);
|
||||
});
|
||||
|
||||
@@ -234,12 +234,20 @@ export async function ensureChromeExtensionRelayServer(opts: {
|
||||
|
||||
const existing = relayRuntimeByPort.get(info.port);
|
||||
if (existing) {
|
||||
return existing.server;
|
||||
if (existing.server.bindHost !== bindHost) {
|
||||
await existing.server.stop();
|
||||
} else {
|
||||
return existing.server;
|
||||
}
|
||||
}
|
||||
|
||||
const inFlight = relayInitByPort.get(info.port);
|
||||
if (inFlight) {
|
||||
return await inFlight;
|
||||
const server = await inFlight;
|
||||
if (server.bindHost === bindHost) {
|
||||
return server;
|
||||
}
|
||||
await server.stop();
|
||||
}
|
||||
|
||||
const extensionReconnectGraceMs = envMsOrDefault(
|
||||
@@ -998,12 +1006,13 @@ export async function ensureChromeExtensionRelayServer(opts: {
|
||||
|
||||
const addr = server.address() as AddressInfo | null;
|
||||
const port = addr?.port ?? info.port;
|
||||
const actualBindHost = addr?.address || bindHost;
|
||||
const host = info.host;
|
||||
const baseUrl = `${new URL(info.baseUrl).protocol}//${host}:${port}`;
|
||||
|
||||
const relay: ChromeExtensionRelayServer = {
|
||||
host,
|
||||
bindHost,
|
||||
bindHost: actualBindHost,
|
||||
port,
|
||||
baseUrl,
|
||||
cdpWsUrl: `ws://${host}:${port}/cdp`,
|
||||
|
||||
@@ -250,6 +250,8 @@ export const FIELD_HELP: Record<string, string> = {
|
||||
"Starting local CDP port used for auto-allocated browser profile ports. Increase this when host-level port defaults conflict with other local services.",
|
||||
"browser.defaultProfile":
|
||||
"Default browser profile name selected when callers do not explicitly choose a profile. Use a stable low-privilege profile as the default to reduce accidental cross-context state use.",
|
||||
"browser.relayBindHost":
|
||||
"Bind IP address for the Chrome extension relay listener. Leave unset for loopback-only access, or set an explicit non-loopback IP such as 0.0.0.0 only when the relay must be reachable across network namespaces (for example WSL2) and the surrounding network is already trusted.",
|
||||
"browser.profiles":
|
||||
"Named browser profile connection map used for explicit routing to CDP ports or URLs with optional metadata. Keep profile names consistent and avoid overlapping endpoint definitions.",
|
||||
"browser.profiles.*.cdpPort":
|
||||
|
||||
@@ -118,6 +118,7 @@ export const FIELD_LABELS: Record<string, string> = {
|
||||
"browser.attachOnly": "Browser Attach-only Mode",
|
||||
"browser.cdpPortRangeStart": "Browser CDP Port Range Start",
|
||||
"browser.defaultProfile": "Browser Default Profile",
|
||||
"browser.relayBindHost": "Browser Relay Bind Address",
|
||||
"browser.profiles": "Browser Profiles",
|
||||
"browser.profiles.*.cdpPort": "Browser Profile CDP Port",
|
||||
"browser.profiles.*.cdpUrl": "Browser Profile CDP URL",
|
||||
|
||||
Reference in New Issue
Block a user