Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): look for a Linux browser on agent-browser's own PATH; name PATH in the unzip error
AdityaUmale635183a15a0b
diff --git a/server/browser/chrome/install.ts b/server/browser/chrome/install.tsindex db04b60ec5..666195b995 100644--- a/server/browser/chrome/install.ts+++ b/server/browser/chrome/install.ts@@ -107,7 +107,7 @@ export const extractZip: Extract = (archive, directory) => new Promise((resolve,execFile(file, args, { timeout: EXTRACT_TIMEOUT_MS, windowsHide: true, maxBuffer: 16 * 1024 * 1024 }, (error) => {if (error) {const noUnzip = file === "unzip" && (error as NodeJS.ErrnoException).code === "ENOENT";- reject(new Error(noUnzip ? "the Chrome archive could not be unpacked: unzip is not installed here (Debian/Ubuntu: sudo apt-get install unzip)" : `the Chrome archive could not be unpacked: ${error.message}`));+ reject(new Error(noUnzip ? "the Chrome archive could not be unpacked: check that unzip is installed and on the server's PATH (Debian/Ubuntu: sudo apt-get install unzip)" : `the Chrome archive could not be unpacked: ${error.message}`));}else resolve();});diff --git a/server/browser/chrome/launcher.ts b/server/browser/chrome/launcher.tsindex f907b6c1e4..14350c3b63 100644--- a/server/browser/chrome/launcher.ts+++ b/server/browser/chrome/launcher.ts@@ -8,6 +8,7 @@ import { userInfo } from "node:os";import { browserEngineStatus } from "../../browser-engine.ts";import { attachesToChrome, ownsBrowserViewport, type BrowserLaunch } from "../../browser-runtime.ts";import { DATA_DIR } from "../../config.ts";+import { augmentedPath } from "../../env-path.ts";import { calibrateIdentity, chromeFingerprint, loadOrCalibrateIdentity, type CalibratedIdentity } from "./calibrate.ts";import { needsNoSandbox, type ChromeIdentity } from "./identity.ts";import { installChromeForTesting, type ChromeForTestingPin, type DownloadProgress } from "./install.ts";@@ -306,4 +307,5 @@ function product(chrome: FoundChrome, identity?: ChromeIdentity): string {return chrome.source === "downloaded" || /for Testing|chrome-(?:linux|mac|win)/iu.test(chrome.path) ? "Chrome for Testing" : "Chromium";}-export const chromeLauncher = new ChromeLauncher({ dataDir: DATA_DIR });+// Linux discovery looks where agent-browser does: it is started with the augmented PATH.+export const chromeLauncher = new ChromeLauncher({ dataDir: DATA_DIR, host: chromeHost({ dataDir: DATA_DIR, enginePath: augmentedPath }) });diff --git a/server/browser/chrome/resolve.test.ts b/server/browser/chrome/resolve.test.tsindex b23157b0eb..02e36bec33 100644--- a/server/browser/chrome/resolve.test.ts+++ b/server/browser/chrome/resolve.test.ts@@ -100,6 +100,9 @@ describe("which Chrome the bots' browser runs", () => {expect(resolveChromePlan(withPath(["/home/ada/.cache/puppeteer/chrome/linux-153.0.8010.47/chrome-linux64/chrome"]), managed)).toEqual(found);expect(resolveChromePlan(withPath(["/home/ada/.cache/ms-playwright/chromium-1200/chrome-linux/chrome"]), managed)).toEqual(found);expect(resolveChromePlan(withPath(["/pw/chromium-1200/chrome-linux64/chrome"], { PLAYWRIGHT_BROWSERS_PATH: "/pw" }), managed)).toEqual(found);+ // agent-browser runs with the augmented PATH, so a browser only there counts too.+ const augmented = { ...host("linux", ["/opt/extra/chromium"], { env: { PATH: "/usr/bin" } }), enginePath: () => "/opt/extra:/usr/bin" };+ expect(resolveChromePlan(augmented, managed)).toEqual(found);// A cache entry without its browser executable is incomplete: the server still downloads.expect(resolveChromePlan(withPath(["/home/ada/.cache/puppeteer/chrome/linux-153.0.8010.47/README"]), managed)).toMatchObject({ kind: "download" });expect(resolveChromePlan(withPath(["/home/ada/.cache/ms-playwright/chromium-1200/INSTALLATION_COMPLETE"]), managed)).toMatchObject({ kind: "download" });diff --git a/server/browser/chrome/resolve.ts b/server/browser/chrome/resolve.tsindex 14fcaef3ea..ca129da889 100644--- a/server/browser/chrome/resolve.ts+++ b/server/browser/chrome/resolve.ts@@ -31,6 +31,8 @@ export interface ChromeHost {registryKeyExists(key: string): boolean;/** LaunchServices' answer for a bundle id on macOS. */appForBundleId(bundleId: string): string | null;+ /** The PATH agent-browser is started with, when it differs from `env.PATH`. */+ enginePath?: () => string;}export interface ChromeEngine {@@ -109,7 +111,7 @@ const LINUX_CACHE_EXECUTABLES = ["chrome-linux64/chrome", "chrome-linux/chrome"]/** 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);+ 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;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))));@@ -165,7 +167,7 @@ function launchServicesApp(bundleId: string): string | null {}/** The registry and LaunchServices take a process each, so each answer is read once per host; files are checked every time. */-export function chromeHost(options: { dataDir: string; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; arch?: string }): ChromeHost {+export function chromeHost(options: { dataDir: string; env?: NodeJS.ProcessEnv; platform?: NodeJS.Platform; arch?: string; enginePath?: () => string }): ChromeHost {const env = options.env ?? process.env;const platform = options.platform ?? process.platform;const answers = new Map<string, string | null>();@@ -178,6 +180,7 @@ export function chromeHost(options: { dataDir: string; env?: NodeJS.ProcessEnv;arch: options.arch ?? process.arch,env,dataDir: options.dataDir,+ ...(options.enginePath ? { enginePath: options.enginePath } : {}),home: (platform === "win32" ? env.USERPROFILE : env.HOME) || homedir(),exists: existsSync,list: (directory) => { try { return readdirSync(directory); } catch { return []; } },