Skip to content

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

fix(browser): find Google Chrome on PATH on a Linux desktop (NixOS)

AdityaUmale360a38f675f1
diff --git a/server/browser/chrome/resolve.test.ts b/server/browser/chrome/resolve.test.ts
index 10fe66fedd..e9548c6cce 100644
--- a/server/browser/chrome/resolve.test.ts
+++ b/server/browser/chrome/resolve.test.ts
@@ -77,6 +77,19 @@ describe("which Chrome the bots' browser runs", () => {
expect(chromePolicyManaged(linuxDesktop(["/etc/opt/chrome/policies/managed/README"]))).toBe(false);
});
+ it("on a Linux desktop finds a Google Chrome that is only on PATH, as on NixOS", () => {
+ const linuxDesktop = (files: string[]) => host("linux", files, { env: { OMB_RESOURCES_PATH: "/opt/OpenMausBot/resources", PATH: "/run/wrappers/bin:/run/current-system/sw/bin:/usr/bin" } });
+ expect(resolveChromePlan(linuxDesktop(["/run/current-system/sw/bin/google-chrome"]), managed))
+ .toEqual({ kind: "chrome", chrome: { path: "/run/current-system/sw/bin/google-chrome", source: "installed" }, fallback: null });
+ expect(resolveChromePlan(linuxDesktop(["/usr/bin/google-chrome-stable", "/usr/bin/google-chrome"]), managed))
+ .toMatchObject({ kind: "chrome", chrome: { path: "/usr/bin/google-chrome-stable", source: "installed" } });
+ expect(resolveChromePlan(linuxDesktop(["/opt/google/chrome/chrome", "/usr/bin/google-chrome"]), managed))
+ .toMatchObject({ kind: "chrome", chrome: { path: "/opt/google/chrome/chrome", source: "installed" } });
+ expect(resolveChromePlan(linuxDesktop(["/usr/bin/chromium"]), managed)).toEqual({ kind: "legacy", reason: "Google Chrome is not installed", noChrome: true });
+ expect(resolveChromePlan(linuxDesktop(["/usr/bin/google-chrome", "/etc/opt/chrome/policies/managed/corp.json"]), managed))
+ .toEqual({ kind: "legacy", reason: "Google Chrome here is managed by an organization" });
+ });
+
it("on a server uses the Chrome for Testing agent-browser installed, newest first", () => {
const server = host("linux", ["/home/ada/.agent-browser/browsers/chrome-152.0.1.2/chrome", "/home/ada/.agent-browser/browsers/chrome-153.0.8010.47/chrome"]);
expect(resolveChromePlan(server, managed)).toEqual({ kind: "chrome", chrome: { path: "/home/ada/.agent-browser/browsers/chrome-153.0.8010.47/chrome", source: "agent-browser" }, fallback: null });
diff --git a/server/browser/chrome/resolve.ts b/server/browser/chrome/resolve.ts
index 8768744add..6717a3ce92 100644
--- a/server/browser/chrome/resolve.ts
+++ b/server/browser/chrome/resolve.ts
@@ -109,11 +109,21 @@ const LINUX_ENGINE_BROWSERS = ["google-chrome", "google-chrome-stable", "google-
/** Where Puppeteer and Playwright unpack Chrome inside a cache entry; an entry without one is incomplete. */
const LINUX_CACHE_EXECUTABLES = ["chrome-linux64/chrome", "chrome-linux/chrome"];
+/** Google Chrome's own launchers, for a Linux desktop whose Chrome is not at Google's install path (NixOS puts it on PATH). */
+const LINUX_CHROME_LAUNCHERS = ["google-chrome-stable", "google-chrome"];
+
+function linuxPath(host: ChromeHost): string[] {
+ return (host.enginePath?.() ?? host.env.PATH ?? "").split(":").filter(Boolean);
+}
+
+function linuxChromeOnPath(host: ChromeHost): string | null {
+ return linuxPath(host).flatMap((directory) => LINUX_CHROME_LAUNCHERS.map((name) => posix.join(directory, name))).find((candidate) => host.exists(candidate)) ?? null;
+}
+
/** 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.enginePath?.() ?? host.env.PATH ?? "").split(":").filter(Boolean);
- if (onPath.some((directory) => LINUX_ENGINE_BROWSERS.some((name) => host.exists(join(directory, name))))) return true;
+ if (linuxPath(host).some((directory) => LINUX_ENGINE_BROWSERS.some((name) => host.exists(join(directory, name))))) return true;
const cached = (directory: string, prefix: string) => host.list(directory)
.some((name) => name.startsWith(prefix) && LINUX_CACHE_EXECUTABLES.some((executable) => host.exists(join(directory, name, executable))));
return cached(join(host.env.PUPPETEER_CACHE_DIR || join(host.home, ".cache", "puppeteer"), "chrome"), "linux")
@@ -132,10 +142,11 @@ export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null,
}
if (!engine?.managed) return { kind: "legacy", reason: "agent-browser was named, so it picks its own browser" };
// The Linux desktop app keeps its bundled browser; a Linux server downloads Chrome for Testing like a Mac.
- const pin = platform === "linux" && env.OMB_RESOURCES_PATH ? null : chromeForTestingPin(platform, host.arch);
- const installed = installedGoogleChrome(host);
+ const linuxDesktop = platform === "linux" && Boolean(env.OMB_RESOURCES_PATH);
+ const pin = linuxDesktop ? null : chromeForTestingPin(platform, host.arch);
+ const installed = installedGoogleChrome(host) ?? (linuxDesktop ? linuxChromeOnPath(host) : null);
if (installed && !chromePolicyManaged(host)) return { kind: "chrome", chrome: { path: installed, source: "installed" }, fallback: pin };
- if (platform === "linux" && env.OMB_RESOURCES_PATH) return installed ? { kind: "legacy", reason: "Google Chrome here is managed by an organization" } : { kind: "legacy", reason: "Google Chrome is not installed", noChrome: true };
+ if (linuxDesktop) return installed ? { kind: "legacy", reason: "Google Chrome here is managed by an organization" } : { kind: "legacy", reason: "Google Chrome is not installed", noChrome: true };
const own = agentBrowserChrome(host);
if (own) return { kind: "chrome", chrome: { path: own, source: "agent-browser" }, fallback: null };
if (pin) {