Skip to content

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

fix(browser): a Linux server where agent-browser already finds a browser keeps it

AdityaUmale92ca23301882
diff --git a/server/browser/chrome/resolve.test.ts b/server/browser/chrome/resolve.test.ts
index f1cf9f64eb..c7029fa390 100644
--- a/server/browser/chrome/resolve.test.ts
+++ b/server/browser/chrome/resolve.test.ts
@@ -92,6 +92,19 @@ describe("which Chrome the bots' browser runs", () => {
expect(resolveChromePlan({ ...host("linux", []), arch: "ia32" }, managed)).toEqual({ kind: "legacy", reason: "no Chrome is installed and none is pinned for this platform" });
});
+ it("on a Linux server keeps a browser agent-browser already finds, rather than downloading another", () => {
+ const found = { kind: "legacy", reason: "agent-browser found a browser on this server" };
+ const withPath = (files: string[], env: NodeJS.ProcessEnv = {}) => host("linux", files, { env: { PATH: "/usr/local/bin:/usr/bin", ...env } });
+ expect(resolveChromePlan(withPath(["/usr/bin/chromium"]), managed)).toEqual(found);
+ expect(resolveChromePlan(withPath(["/usr/local/bin/google-chrome-stable"]), managed)).toEqual(found);
+ expect(resolveChromePlan(withPath(["/home/ada/.cache/puppeteer/chrome/linux-153.0.8010.47"]), managed)).toEqual(found);
+ expect(resolveChromePlan(withPath(["/home/ada/.cache/ms-playwright/chromium-1200"]), managed)).toEqual(found);
+ expect(resolveChromePlan(withPath(["/pw/chromium-1200"], { PLAYWRIGHT_BROWSERS_PATH: "/pw" }), managed)).toEqual(found);
+ expect(resolveChromePlan(withPath(["/home/ada/.cache/ms-playwright/firefox-1500", "/opt/firefox/firefox"]), managed)).toMatchObject({ kind: "download" });
+ const downloaded = chromeForTestingExecutable("/data", chromeForTestingPin("linux", "arm64")!);
+ expect(resolveChromePlan(withPath(["/usr/bin/chromium", downloaded]), managed)).toMatchObject({ kind: "chrome", chrome: { source: "downloaded" } });
+ });
+
it("wraps a Chrome named by the environment, as the Docker image names its Chrome for Testing", () => {
const named = (env: NodeJS.ProcessEnv, files: string[]) => host("linux", files, { env });
expect(resolveChromePlan(named({ AGENT_BROWSER_EXECUTABLE_PATH: "/opt/openmausbot-browser/chrome" }, ["/opt/openmausbot-browser/chrome"]), null))
diff --git a/server/browser/chrome/resolve.ts b/server/browser/chrome/resolve.ts
index 5e11288b96..59f3309883 100644
--- a/server/browser/chrome/resolve.ts
+++ b/server/browser/chrome/resolve.ts
@@ -100,6 +100,18 @@ export function agentBrowserChrome(host: ChromeHost): string | null {
return versions.map((version) => join(browsers, version, layout)).find((candidate) => host.exists(candidate)) ?? null;
}
+/** agent-browser's own search on Linux: these browsers on PATH, then Puppeteer's and Playwright's caches. */
+const LINUX_ENGINE_BROWSERS = ["google-chrome", "google-chrome-stable", "google-chrome-unstable", "chromium", "chromium-browser", "brave-browser", "brave-browser-stable"];
+
+/** A Linux server where agent-browser already finds a browser keeps it rather than downloading another. */
+export function engineFindsLinuxBrowser(host: ChromeHost): boolean {
+ const { join } = posix;
+ const onPath = (host.env.PATH ?? "").split(":").filter(Boolean);
+ if (onPath.some((directory) => LINUX_ENGINE_BROWSERS.some((name) => host.exists(join(directory, name))))) return true;
+ if (host.list(join(host.env.PUPPETEER_CACHE_DIR || join(host.home, ".cache", "puppeteer"), "chrome")).length) return true;
+ return host.list(host.env.PLAYWRIGHT_BROWSERS_PATH || join(host.home, ".cache", "ms-playwright")).some((name) => name.startsWith("chromium"));
+}
+
export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null): ChromePlan {
const { env, platform } = host;
if (env.OMB_BROWSER_LEGACY_SHELL?.trim() === "1") return { kind: "legacy", reason: "OMB_BROWSER_LEGACY_SHELL=1" };
@@ -119,7 +131,9 @@ export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null)
if (own) return { kind: "chrome", chrome: { path: own, source: "agent-browser" }, fallback: null };
if (pin) {
const executable = chromeForTestingExecutable(host.dataDir, pin);
- return host.exists(executable) ? { kind: "chrome", chrome: { path: executable, source: "downloaded" }, fallback: null } : { kind: "download", pin };
+ if (host.exists(executable)) return { kind: "chrome", chrome: { path: executable, source: "downloaded" }, fallback: null };
+ if (platform === "linux" && engineFindsLinuxBrowser(host)) return { kind: "legacy", reason: "agent-browser found a browser on this server" };
+ return { kind: "download", pin };
}
return { kind: "legacy", reason: installed ? "Google Chrome here is managed by an organization" : "no Chrome is installed and none is pinned for this platform" };
}