mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-27 06:10:41 +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`,
|
||||
|
||||
Reference in New Issue
Block a user