Skip to content

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

fix(browser): give the library install advice in the first part, on Linux only

AdityaUmaleb7b317d3ee32
diff --git a/server/browser-tool-shape.test.ts b/server/browser-tool-shape.test.ts
index 77a9719911..556c0d190f 100644
--- a/server/browser-tool-shape.test.ts
+++ b/server/browser-tool-shape.test.ts
@@ -76,14 +76,25 @@ describe("browser tool shaping", () => {
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);
+ const platform = process.platform;
+ const shape = (result: unknown) => shapeBrowserToolResult(result) as { content: Array<{ text: string }>; isError?: boolean };
+ try {
+ Object.defineProperty(process, "platform", { value: "linux" });
+ const shaped = shape({ content: [{ type: "text", text: launch }], isError: true });
+ expect(shaped.isError).toBe(true);
+ expect(shaped.content).toHaveLength(1);
+ expect(shaped.content[0].text.startsWith(launch)).toBe(true);
+ expect(shaped.content[0].text).toContain("missing libraries the browser needs (libatk-1.0.so.0)");
+ expect(shaped.content[0].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(shape(result).content).toEqual(result.content);
+ }
+ // the install command is for Linux hosts only
+ Object.defineProperty(process, "platform", { value: "darwin" });
+ expect(shape({ content: [{ type: "text", text: launch }], isError: true }).content[0].text).toBe(launch);
+ } finally {
+ Object.defineProperty(process, "platform", { value: platform });
}
});
diff --git a/server/browser-tool-shape.ts b/server/browser-tool-shape.ts
index 40705410aa..e5828c975d 100644
--- a/server/browser-tool-shape.ts
+++ b/server/browser-tool-shape.ts
@@ -154,14 +154,18 @@ export function shapeBrowserToolResult(result: unknown, options: { toolName?: st
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);
+ if (result.isError === true && process.platform === "linux") 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 });
+ // The advice joins the first text part: older Claude Code shows a bot only that one.
+ if (library) {
+ const first = content.find((part): part is { text: string } => isRecord(part) && part.type === "text" && typeof part.text === "string");
+ if (first) first.text += `\n\n${new BrowserHostError("libraries", [library]).message}`;
+ }
return { ...Object.fromEntries(Object.entries(result).filter(([key]) => key !== "structuredContent")), content };
}