Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Browser loopback hint only on self-hosted servers (#5229)

milind-sonif6cdbb8bd3a7
diff --git a/server/drivers/chat-mcp-browser-args.test.ts b/server/drivers/chat-mcp-browser-args.test.ts
index ea53365f02..98dd437fee 100644
--- a/server/drivers/chat-mcp-browser-args.test.ts
+++ b/server/drivers/chat-mcp-browser-args.test.ts
@@ -43,4 +43,14 @@ describe("loopbackNavigationHint", () => {
expect(loopbackNavigationHint("agent_browser_open", { url: "http://localhost:3000/" }, "Opened http://localhost:3000/ in t1.")).toBe("");
expect(loopbackNavigationHint("agent_browser_read", { url: "http://127.0.0.1/" }, "failed")).toBe("");
});
+
+ it("stays quiet where the browser runs on the person's computer or the setting does not exist", () => {
+ const failed = ["agent_browser_open", { url: "http://127.0.0.1:8188/" }, "Navigation to http://127.0.0.1:8188/ failed: ERR_SOCKS_CONNECTION_FAILED"] as const;
+ expect(loopbackNavigationHint(...failed, {})).toMatch(/Open sites on this server/);
+ // The desktop app: the browser and its loopback are the person's own computer.
+ expect(loopbackNavigationHint(...failed, { OMB_DESKTOP_PARENT: "1" })).toBe("");
+ // A Cloud home has no "Open sites on this server" row.
+ expect(loopbackNavigationHint(...failed, { OMB_CLOUD_ROLE: "home" })).toBe("");
+ expect(loopbackNavigationHint(...failed, { OMB_CLOUD_MACHINE_ID: "m-1" })).toBe("");
+ });
});
diff --git a/server/drivers/chat-mcp-tools.ts b/server/drivers/chat-mcp-tools.ts
index 98112bf9ec..bf930fe239 100644
--- a/server/drivers/chat-mcp-tools.ts
+++ b/server/drivers/chat-mcp-tools.ts
@@ -9,6 +9,7 @@ import type { SendTurnInput } from "../contracts.ts";
import { redactSecretsInText } from "../redact.ts";
import { MESSAGE_FILE_MAX_BYTES } from "../message-file.ts";
import { augmentedPath } from "../env-path.ts";
+import { cloudHomeConfigured } from "../cloud-home.ts";
import { killCliTree, spawnCli } from "../procs.ts";
import { AGENTS_TOOL_ALIASES } from "../../shared/agents-tool-names.ts";
import { bridgedCallTarget, unbridgedServer } from "./agents-bridge.ts";
@@ -375,9 +376,11 @@ export function normalizeBuiltInBrowserArgs(tool: string, args: unknown): void {
if (args.ref !== undefined || args.selector !== undefined) { delete args.x; delete args.y; }
}
-/** The browser runs on the server; 127.0.0.1 there is the server itself, not the person's computer. Say so on the
- * failed navigation instead of leaving only ERR_SOCKS_CONNECTION_FAILED, and point at the LAN address to use. */
-export function loopbackNavigationHint(tool: string, args: unknown, text: string): string {
+/** On a self-hosted server the browser runs on the server; 127.0.0.1 there is the server itself, not the person's computer.
+ * Say so on the failed navigation instead of leaving only ERR_SOCKS_CONNECTION_FAILED, and point at the LAN address to use.
+ * Not on the desktop app, where the browser runs on the person's own computer, nor on a Cloud home, which has no such setting. */
+export function loopbackNavigationHint(tool: string, args: unknown, text: string, env: NodeJS.ProcessEnv = process.env): string {
+ if (env.OMB_DESKTOP_PARENT === "1" || cloudHomeConfigured(env)) return "";
if (!/^agent_browser_(?:open|navigate)$/u.test(tool) || !object(args) || typeof args.url !== "string") return "";
if (!ROUTE_LOOPBACK.test(args.url.trim()) || !/(?:ERR_[A-Z_]+|failed)/u.test(text)) return "";
return " That address is the loopback of the machine running this browser, not your own computer: open the site by the LAN address it answers on (for example http://192.168.1.20:8188), which must be reachable from the server, and allow it under Settings → Browser → Open sites on this server.";