Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): keep a started Chrome download when a Linux browser appears on PATH later
AdityaUmale55fcba9d4567
diff --git a/server/browser/chrome/launcher.test.ts b/server/browser/chrome/launcher.test.tsindex 1e6896abf0..c3b40f2bda 100644--- a/server/browser/chrome/launcher.test.ts+++ b/server/browser/chrome/launcher.test.ts@@ -114,6 +114,39 @@ describe("the Chrome launcher", () => {expect(chrome.describe()).toBe("Chrome for Testing 153 (downloaded)");});+ it("on a Linux server keeps the download it started when agent-browser's PATH later shows a browser", async () => {+ const root = mkdtempSync(join(tmpdir(), "omb-launcher-"));+ folders.push(root);+ let enginePath = posix.join(root, "bin");+ const env = { HOME: root };+ const real = chromeHost({ dataDir: join(root, "data"), env, platform: "linux", arch: "x64", enginePath: () => enginePath });+ const host = { ...real, exists: (path: string) => path.startsWith(root) && existsSync(path), list: (folder: string) => folder.startsWith(root) ? real.list(folder) : [] };+ let finish!: () => void;+ const install = vi.fn(async (options: Parameters<typeof installChromeForTesting>[0]) => {+ await new Promise<void>((resolve) => { finish = resolve; });+ const path = chromeForTestingExecutable(options.dataDir, options.pin);+ mkdirSync(dirname(path), { recursive: true });+ writeFileSync(path, "#!/bin/sh\n", { mode: 0o755 });+ return path;+ });+ const chrome = new ChromeLauncher({+ dataDir: join(root, "data"), env, platform: "linux", arch: "x64", host, engine: () => ({ managed: true }), install,+ calibrate: async () => identity("153", "Not_A Brand"), screen: async () => ({ width: 1440, height: 900 }), sidecars: sidecars(), log: () => {}, checkLauncher: async () => {},+ });+ const launching = { AGENT_BROWSER_EXECUTABLE_PATH: chrome.path, AGENT_BROWSER_HIDE_SCROLLBARS: "0" };+ expect(chrome.env()).toEqual(launching);+ await vi.waitFor(() => expect(install).toHaveBeenCalledOnce());+ // The login shell's PATH arrives while Chrome for Testing downloads, with a Chromium on it.+ mkdirSync(join(root, "extra"), { recursive: true });+ writeFileSync(join(root, "extra", "chromium"), "#!/bin/sh\n", { mode: 0o755 });+ enginePath = posix.join(root, "extra");+ expect(chrome.env()).toEqual(launching);+ finish();+ await chrome.prepare();+ expect(chrome.env()).toEqual(launching);+ expect(install).toHaveBeenCalledOnce();+ });+it("uses Chrome for Testing when the installed Google Chrome cannot start headless", async () => {const machine = mac();const install = vi.fn(async (options: Parameters<typeof installChromeForTesting>[0]) => {diff --git a/server/browser/chrome/launcher.ts b/server/browser/chrome/launcher.tsindex 14350c3b63..7b7e5732b5 100644--- a/server/browser/chrome/launcher.ts+++ b/server/browser/chrome/launcher.ts@@ -107,7 +107,9 @@ export class ChromeLauncher implements BrowserLaunch {}plan(): ChromePlan {- return resolveChromePlan(this.host, this.options.engine ? this.options.engine() : this.managedEngine());+ // Once a download has started, a browser agent-browser's PATH shows later must not switch a session's launcher.+ const downloading = this.state.kind === "preparing" || this.state.kind === "downloading";+ return resolveChromePlan(this.host, this.options.engine ? this.options.engine() : this.managedEngine(), { downloading });}/** What agent-browser's environment gains: nothing while the engine keeps its own browser. */diff --git a/server/browser/chrome/resolve.ts b/server/browser/chrome/resolve.tsindex ca129da889..527473ed36 100644--- a/server/browser/chrome/resolve.ts+++ b/server/browser/chrome/resolve.ts@@ -119,7 +119,8 @@ export function engineFindsLinuxBrowser(host: ChromeHost): boolean {|| cached(host.env.PLAYWRIGHT_BROWSERS_PATH || join(host.home, ".cache", "ms-playwright"), "chromium-");}-export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null): ChromePlan {+/** `downloading`: a Chrome for Testing download is under way, so a browser agent-browser finds later does not replace it. */+export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null, options: { downloading?: boolean } = {}): ChromePlan {const { env, platform } = host;if (env.OMB_BROWSER_LEGACY_SHELL?.trim() === "1") return { kind: "legacy", reason: "OMB_BROWSER_LEGACY_SHELL=1" };const named = env.OMB_CHROME_PATH?.trim() || env.AGENT_BROWSER_EXECUTABLE_PATH?.trim();@@ -139,7 +140,7 @@ export function resolveChromePlan(host: ChromeHost, engine: ChromeEngine | null)if (pin) {const executable = chromeForTestingExecutable(host.dataDir, 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" };+ if (platform === "linux" && !options.downloading && 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" };