Skip to content

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

fix(browser): stop pointing at `openmausbot browser setup`, which does not exist

AdityaUmale707e50c12978
diff --git a/server/browser/chrome/host-setup.test.ts b/server/browser/chrome/host-setup.test.ts
index f6af64a0a3..e09c66d962 100644
--- a/server/browser/chrome/host-setup.test.ts
+++ b/server/browser/chrome/host-setup.test.ts
@@ -4,7 +4,7 @@ import { join } from "node:path";
import { afterAll, describe, expect, it } from "vitest";
import { removeTempDir } from "../../testing/cleanup.ts";
-import { appArmorProfile, BrowserHostError, diagnoseLaunchFailure, missingLibraries, sandboxBlocked, sandboxDisabled, USERNS_RESTRICTION } from "./host-setup.ts";
+import { appArmorProfile, BrowserHostError, diagnoseLaunchFailure, LIBRARIES_COMMAND, missingLibraries, SANDBOX_STEPS_URL, sandboxBlocked, sandboxDisabled, USERNS_RESTRICTION } from "./host-setup.ts";
const folders: string[] = [];
afterAll(async () => { for (const folder of folders) await removeTempDir(folder); });
@@ -21,7 +21,16 @@ describe("host setup", () => {
const diagnosis = await diagnoseLaunchFailure({ executable: "/opt/chrome", output: "[0101/000000.000:FATAL:zygote_host_impl_linux.cc] No usable sandbox! ...", platform: "darwin" });
expect(diagnosis).toBeInstanceOf(BrowserHostError);
expect(diagnosis?.kind).toBe("sandbox");
- expect(diagnosis?.message).toMatch(/openmausbot browser setup/);
+ expect(diagnosis?.message).toContain(SANDBOX_STEPS_URL);
+ expect(diagnosis?.message).not.toMatch(/browser setup/);
+ // The linked steps exist, and the viewer offers the same link and command.
+ expect(readFileSync(new URL("../../../docs/deploy-vps.md", import.meta.url), "utf8")).toMatch(/^### Ubuntu 24\.04 browser sandbox$/m);
+ expect(SANDBOX_STEPS_URL.endsWith("/docs/deploy-vps.md#ubuntu-2404-browser-sandbox")).toBe(true);
+ const viewer = readFileSync(new URL("../../../src/lib/browser-stream-client.ts", import.meta.url), "utf8");
+ expect(viewer).toContain(`"${SANDBOX_STEPS_URL}"`);
+ expect(viewer).toContain(`"${LIBRARIES_COMMAND}"`);
+ expect(LIBRARIES_COMMAND).toBe("sudo openmausbot browser install --with-deps");
+ expect(new BrowserHostError("libraries", ["libnss3.so"]).message).toContain(LIBRARIES_COMMAND);
expect(await diagnoseLaunchFailure({ executable: "/opt/chrome", output: "something else", platform: "darwin" })).toBeNull();
expect(sandboxDisabled({})).toBe(false);
expect(sandboxDisabled({ OMB_BROWSER_SANDBOX: "0" })).toBe(true);
diff --git a/server/browser/chrome/host-setup.ts b/server/browser/chrome/host-setup.ts
index 3c4d1c0c29..dae580c233 100644
--- a/server/browser/chrome/host-setup.ts
+++ b/server/browser/chrome/host-setup.ts
@@ -5,7 +5,7 @@
// exact executable instead of a wildcard path.
//
// OMB never turns Chrome's sandbox off by itself on a host. A host that cannot
-// give it one gets the setup command instead, and only an operator's explicit
+// give it one gets the manual setup steps instead, and only an operator's explicit
// OMB_BROWSER_SANDBOX=0 launches without it. The computer container image (also
// run on a VPS) is the exception: it drops capabilities, so its Chrome runs
// without its own sandbox and the container is the isolation boundary.
@@ -14,7 +14,10 @@ import { execFile } from "node:child_process";
import { existsSync, readFileSync } from "node:fs";
import { isAbsolute } from "node:path";
-export const SETUP_COMMAND = "sudo openmausbot browser setup";
+/** Installs the Linux libraries Chrome needs (as root, once). */
+export const LIBRARIES_COMMAND = "sudo openmausbot browser install --with-deps";
+/** There is no command for the sandbox: an administrator allows one root-owned Chrome by hand. */
+export const SANDBOX_STEPS_URL = "https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox";
/** What Chrome prints before aborting when it cannot sandbox itself. */
export const NO_SANDBOX_SIGNATURE = "No usable sandbox";
@@ -37,7 +40,7 @@ export function appArmorProfile(executable: string): string {
if (!isAbsolute(executable) || /[\s*?[\]{}"'\\^]/.test(executable) || !executable.startsWith("/opt/")) {
throw new Error(`The browser's AppArmor exemption is only for a root-owned path under /opt, not ${executable}.`);
}
- return `# Written by \`openmausbot browser setup\`: lets OpenMausBot's Chrome use its sandbox.
+ return `# Written for OpenMausBot: lets its Chrome use its sandbox.
abi <abi/4.0>,
include <tunables/global>
@@ -83,8 +86,8 @@ export class BrowserHostError extends Error {
constructor(kind: "sandbox" | "libraries", libraries: readonly string[] = []) {
super(kind === "sandbox"
- ? `This host blocks the sandbox the browser runs in (AppArmor on Ubuntu 23.10+). Run \`${SETUP_COMMAND}\` on the host once to allow it, then try again.`
- : `This host is missing libraries the browser needs (${libraries.join(", ")}). Run \`${SETUP_COMMAND}\` on the host to install them, then try again.`);
+ ? `This host blocks the sandbox the browser runs in (AppArmor on Ubuntu 23.10+). An administrator can allow it for one root-owned copy of Chrome, following ${SANDBOX_STEPS_URL}, then try again.`
+ : `This host is missing libraries the browser needs (${libraries.join(", ")}). Run \`${LIBRARIES_COMMAND}\` on the host to install them, then try again.`);
this.name = "BrowserHostError";
this.kind = kind;
this.libraries = libraries;
diff --git a/server/browser/viewers/stream-v2.ts b/server/browser/viewers/stream-v2.ts
index 52f734d1fd..510747fb7f 100644
--- a/server/browser/viewers/stream-v2.ts
+++ b/server/browser/viewers/stream-v2.ts
@@ -11,7 +11,7 @@ import type { Socket } from "node:net";
import { WebSocketServer, type RawData, type WebSocket } from "ws";
-import { BrowserHostError, SETUP_COMMAND } from "../chrome/host-setup.ts";
+import { BrowserHostError } from "../chrome/host-setup.ts";
import type { BrowserService, BrowserTarget } from "../service.ts";
import { FRAME_CAP_LIMITS, type Viewer, type ViewerOptions, type ViewerOutput } from "./core.ts";
import { requestedSize } from "./viewport.ts";
@@ -306,7 +306,8 @@ export class StreamV2 {
if (session.closed || session.closing) await viewer.close({ dropped: session.lost && session.theirs() });
else session.attached(viewer, this.#service);
} catch (error) {
- if (error instanceof BrowserHostError) session.close(STREAM_CLOSE.hostSetup, JSON.stringify({ need: error.kind, command: SETUP_COMMAND }));
+ // The viewer knows the fix for each need: a close reason holds at most 123 bytes, too few for the steps link.
+ if (error instanceof BrowserHostError) session.close(STREAM_CLOSE.hostSetup, JSON.stringify({ need: error.kind }));
else session.close(STREAM_CLOSE.failed, "The browser could not start.");
}
}
diff --git a/server/routes/browser-viewers.test.ts b/server/routes/browser-viewers.test.ts
index 35c32644a5..f129756446 100644
--- a/server/routes/browser-viewers.test.ts
+++ b/server/routes/browser-viewers.test.ts
@@ -8,7 +8,7 @@ import { tmpdir } from "node:os";
import { basename, join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
-import { BrowserHostError, SETUP_COMMAND } from "../browser/chrome/host-setup.ts";
+import { BrowserHostError } from "../browser/chrome/host-setup.ts";
import type { Audience } from "../audience.ts";
import type { Download } from "../browser/cdp/downloads.ts";
import type { BrowserService } from "../browser/service.ts";
@@ -310,12 +310,12 @@ describe("the v2 stream", () => {
it.each([
{ error: new BrowserHostError("sandbox"), need: "sandbox" },
{ error: new BrowserHostError("libraries", ["libnss3.so"]), need: "libraries" },
- ])("tells viewers the command that sets up the host ($need)", async ({ error, need }) => {
+ ])("tells viewers what the host needs ($need), never a command that does not exist", async ({ error, need }) => {
const fixture = await serve({ attach: async () => { throw error; } });
const socket = new WebSocket(`ws://${fixture.origin}/api/bots/pepper/browser/stream`);
const { code, reason } = await new Promise<{ code: number; reason: string }>((resolve) => socket.addEventListener("close", (event) => resolve({ code: event.code, reason: event.reason })));
expect(code).toBe(STREAM_CLOSE.hostSetup);
- expect(JSON.parse(reason)).toEqual({ need, command: SETUP_COMMAND });
+ expect(JSON.parse(reason)).toEqual({ need });
});
});
diff --git a/src/components/browser/StreamSurface.tsx b/src/components/browser/StreamSurface.tsx
index f89dacbcbf..e625821bb2 100644
--- a/src/components/browser/StreamSurface.tsx
+++ b/src/components/browser/StreamSurface.tsx
@@ -19,6 +19,7 @@ import {
import {
createPreviewFramePainter,
+ PREVIEW_STREAM_SANDBOX_STEPS_URL,
previewStreamHostSetupMessage,
previewStreamModifiers,
uploadPreviewStreamFiles,
@@ -763,7 +764,11 @@ export function StreamSurface(props: {
{hostSetup ? (
<div className="absolute inset-0 z-30 flex flex-col items-center justify-center gap-3 bg-card p-4 text-center">
<p role="alert" className="max-w-sm text-[13px] text-ink-secondary">{previewStreamHostSetupMessage(hostSetup)}</p>
- <code className="max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink">{hostSetup.command}</code>
+ {hostSetup.need === "libraries" ? (
+ <code className="max-w-md select-all break-all rounded-lg bg-inset px-3 py-2 text-left text-[12px] text-ink">{hostSetup.command}</code>
+ ) : (
+ <a href={PREVIEW_STREAM_SANDBOX_STEPS_URL} target="_blank" rel="noopener noreferrer" className="text-[12px] text-ink underline">Browser sandbox setup steps</a>
+ )}
<button type="button" className="rounded-lg border border-hairline px-3 py-1.5 text-[12px] text-ink hover:bg-inset" onClick={() => setHostSetup(null)}>Try again</button>
</div>
) : null}
diff --git a/src/lib/browser-stream-client.test.ts b/src/lib/browser-stream-client.test.ts
index cea2a620c8..a2d6fef009 100644
--- a/src/lib/browser-stream-client.test.ts
+++ b/src/lib/browser-stream-client.test.ts
@@ -201,8 +201,18 @@ describe("preview stream downloads, uploads and messages", () => {
FakeSocket.current.closeWith(4404, "gone");
expect(onGone).toHaveBeenCalledOnce();
createPreviewStreamClient(target, events({ onHostSetup }));
+ FakeSocket.current.closeWith(4503, JSON.stringify({ need: "libraries" }));
+ expect(onHostSetup).toHaveBeenCalledWith({ need: "libraries", command: "sudo openmausbot browser install --with-deps" });
+ // An older server named a command that never existed: the viewer shows the real command, or the steps.
+ createPreviewStreamClient(target, events({ onHostSetup }));
FakeSocket.current.closeWith(4503, JSON.stringify({ need: "libraries", command: "sudo openmausbot browser setup" }));
- expect(onHostSetup).toHaveBeenCalledWith({ need: "libraries", command: "sudo openmausbot browser setup" });
+ expect(onHostSetup).toHaveBeenLastCalledWith({ need: "libraries", command: "sudo openmausbot browser install --with-deps" });
+ createPreviewStreamClient(target, events({ onHostSetup }));
+ FakeSocket.current.closeWith(4503, JSON.stringify({ need: "sandbox", command: "sudo openmausbot browser setup" }));
+ expect(onHostSetup).toHaveBeenLastCalledWith({ need: "sandbox" });
+ createPreviewStreamClient(target, events({ onHostSetup }));
+ FakeSocket.current.closeWith(4503, "not json");
+ expect(onHostSetup).toHaveBeenLastCalledWith({ need: "sandbox" });
createPreviewStreamClient(target, events({ onUnauthorized }));
FakeSocket.current.closeWith(1006, "", false);
expect(onUnauthorized).toHaveBeenCalledOnce();
diff --git a/src/lib/browser-stream-client.ts b/src/lib/browser-stream-client.ts
index 09e0163091..cfde7878c1 100644
--- a/src/lib/browser-stream-client.ts
+++ b/src/lib/browser-stream-client.ts
@@ -7,10 +7,15 @@
export const PREVIEW_STREAM_HOST_SETUP_CLOSE_CODE = 4503;
export const PREVIEW_STREAM_TAB_GONE_CODE = 4404;
-export interface PreviewStreamHostSetup {
- readonly need: "sandbox" | "libraries";
- readonly command: string;
-}
+/** A sandbox has no command to run, only steps for an administrator; missing libraries have one. */
+export type PreviewStreamHostSetup =
+ | { readonly need: "sandbox" }
+ | { readonly need: "libraries"; readonly command: string };
+
+/** The server's LIBRARIES_COMMAND and SANDBOX_STEPS_URL: a close reason is too short to carry the link. */
+export const PREVIEW_STREAM_LIBRARIES_COMMAND = "sudo openmausbot browser install --with-deps";
+export const PREVIEW_STREAM_SANDBOX_STEPS_URL =
+ "https://github.com/milind-soni/OpenMausBot/blob/main/docs/deploy-vps.md#ubuntu-2404-browser-sandbox";
export type PreviewViewportSetting =
| { readonly mode: "fill" }
@@ -532,22 +537,17 @@ export function createPreviewFramePainter(
};
}
-/** A malformed reason still stops the viewer and offers the usual command. */
+/** A malformed reason still stops the viewer, with the sandbox steps. */
const decodeHostSetup = (reason: string): PreviewStreamHostSetup => {
try {
- const value = JSON.parse(reason) as Partial<PreviewStreamHostSetup>;
- if (
- (value.need === "sandbox" || value.need === "libraries") &&
- typeof value.command === "string"
- ) {
- return { need: value.need, command: value.command };
- }
+ // An older server's command for either need was `openmausbot browser setup`, which never existed.
+ if ((JSON.parse(reason) as { need?: unknown }).need === "libraries") return { need: "libraries", command: PREVIEW_STREAM_LIBRARIES_COMMAND };
} catch {}
- return { need: "sandbox", command: "sudo openmausbot browser setup" };
+ return { need: "sandbox" };
};
-/** What a viewer tells the person; `command` is shown beside it, ready to copy. */
+/** What a viewer tells the person; beside it, the libraries `command` ready to copy or a link to the sandbox steps. */
export const previewStreamHostSetupMessage = (setup: PreviewStreamHostSetup) =>
setup.need === "sandbox"
- ? "This server's host blocks the sandbox its browser runs in. Run this once on the host, then try again:"
+ ? "This server's host blocks the sandbox its browser runs in. An administrator can allow it for one copy of Chrome with these steps, then try again:"
: "This server's host is missing libraries its browser needs. Run this once on the host, then try again:";