Skip to content

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

fix(browser): tell the bot how to install missing Chrome libraries

AdityaUmale4715b1620db0
diff --git a/server/browser-tool-shape.test.ts b/server/browser-tool-shape.test.ts
index 30be857515..77a9719911 100644
--- a/server/browser-tool-shape.test.ts
+++ b/server/browser-tool-shape.test.ts
@@ -74,6 +74,19 @@ describe("browser tool shaping", () => {
expect(shapeBrowserToolResult({ error: "x" })).toEqual({ error: "x" });
});
+ it("tells the bot the install command when Chrome cannot load a system library", () => {
+ const launch = "Chrome exited early (exit code: 127) without writing DevToolsActivePort\nChrome stderr:\n /home/maus/.agent-browser/browsers/chrome-157.0.8103.38/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory";
+ const shaped = shapeBrowserToolResult({ content: [{ type: "text", text: launch }], isError: true }) as { content: Array<{ text: string }>; isError: boolean };
+ expect(shaped.isError).toBe(true);
+ expect(shaped.content[0].text).toBe(launch);
+ expect(shaped.content[1].text).toContain("libatk-1.0.so.0");
+ expect(shaped.content[1].text).toContain("`sudo openmausbot browser install --with-deps`");
+ // a page that merely mentions the loader's words, or another failure, gets no install advice
+ for (const result of [{ content: [{ type: "text", text: launch }] }, { content: [{ type: "text", text: "Chrome exited early (exit code: 1)" }], isError: true }]) {
+ expect((shapeBrowserToolResult(result) as { content: unknown[] }).content).toHaveLength(1);
+ }
+ });
+
it("cuts oversized text to the budget and says how to narrow the next call", () => {
const text = "line of accessibility tree\n".repeat(4_000);
const shaped = shapeBrowserToolResult({ content: [{ type: "text", text }], structuredContent: {} }, { toolName: "agent_browser_snapshot" }) as { content: Array<{ text: string }> };
diff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.ts
index 7927a2af75..40705410aa 100644
--- a/server/browser-tool-shape.ts
+++ b/server/browser-tool-shape.ts
@@ -1,5 +1,6 @@
// agent-browser 0.37.0's core profile advertises 29 tools at ~12.5k tokens, mostly fifteen launch/session parameters
// repeated on every tool, and every result arrives twice (text plus a 3-5x larger structuredContent that Codex keeps in history).
+import { BrowserHostError, loaderMissingLibrary } from "./browser/chrome/host-setup.ts";
import { trimResultText } from "./mcp-trim.ts";
/** A model must never set these: `session` reaches another bot's browser, `extraArgs`/`caCert`/`headed`/`webgpu`/`webmcp`
@@ -149,13 +150,18 @@ export function shapeBrowserToolResult(result: unknown, options: { toolName?: st
if (!isRecord(result) || !Array.isArray(result.content)) return result;
const budget = options.budget ?? DEFAULT_BROWSER_RESULT_BUDGET;
let textParts = 0;
+ let library: string | undefined;
const content = (result.content as unknown[]).map((part) => {
if (!isRecord(part) || part.type !== "text" || typeof part.text !== "string") return part;
textParts++;
+ if (result.isError === true) library ??= loaderMissingLibrary(part.text);
const outcome = trimResultText({ text: withoutLifecycle(part.text), budget, toolName: options.toolName });
return { ...part, text: outcome.trimmed ? outcome.text + BROWSER_NARROWING_HINT : outcome.text };
});
if (!textParts) return { ...result, content };
+ // agent-browser launches Chrome itself, so a host missing system libraries
+ // only shows the loader's words; say how to install them, as our own launch does.
+ if (library) content.push({ type: "text", text: new BrowserHostError("libraries", [library]).message });
return { ...Object.fromEntries(Object.entries(result).filter(([key]) => key !== "structuredContent")), content };
}
diff --git a/server/browser/chrome/host-setup.ts b/server/browser/chrome/host-setup.ts
index dae580c233..0af45af61e 100644
--- a/server/browser/chrome/host-setup.ts
+++ b/server/browser/chrome/host-setup.ts
@@ -98,6 +98,11 @@ const MISSING_LIBRARY = /^\s*(\S+) => not found$/gm;
/** glibc's loader abort, naming the first library it could not load. */
const LOADER_ERROR = /error while loading shared libraries: ([^:\s]+)/;
+/** The library glibc's loader names in a failed launch's output, if any. */
+export function loaderMissingLibrary(output: string): string | undefined {
+ return LOADER_ERROR.exec(output)?.[1];
+}
+
function run(command: string, args: readonly string[], env: NodeJS.ProcessEnv): Promise<string> {
return new Promise((resolve) => {
execFile(command, [...args], { timeout: 5_000, encoding: "utf8", windowsHide: true, env }, (_error, stdout, stderr) => resolve(`${stdout ?? ""}${stderr ?? ""}`));
@@ -111,7 +116,7 @@ function run(command: string, args: readonly string[], env: NodeJS.ProcessEnv):
* libraries a host provides another way (NixOS's nix-ld).
*/
export async function missingLibraries(executable: string, env: NodeJS.ProcessEnv = process.env): Promise<string[]> {
- const loaderError = LOADER_ERROR.exec(await run(executable, ["--version"], env))?.[1];
+ const loaderError = loaderMissingLibrary(await run(executable, ["--version"], env));
if (loaderError === undefined) return [];
const listed = [...(await run("ldd", [executable], env)).matchAll(MISSING_LIBRARY)].map((match) => match[1]!);
return listed.length > 0 ? listed : [loaderError];