Skip to content

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

browser panel: show a Cloud browser's window as a remote desktop when the server offers it

milind-soni575eac749920
diff --git a/src/components/BrowserPanel.desktop.dom.test.ts b/src/components/BrowserPanel.desktop.dom.test.ts
new file mode 100644
index 0000000000..bc1ae601e8
--- /dev/null
+++ b/src/components/BrowserPanel.desktop.dom.test.ts
@@ -0,0 +1,79 @@
+// @vitest-environment happy-dom
+// A Cloud browser shown as a remote desktop: the panel opens its stream without pictures, shows the desktop view once
+// that stream says the browser runs, and keeps it over the picture's rectangle.
+import { act, createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import type { Bot } from "@/state/store";
+
+type SurfaceProps = {
+ connect: (target: { width: number; height: number }, events: unknown) => unknown;
+ onConnectedChange?: (connected: boolean) => void;
+ onMessage?: (message: Record<string, unknown>) => void;
+ onControl?: (control: unknown) => void;
+};
+const surfaces = vi.hoisted(() => [] as SurfaceProps[]);
+const streams = vi.hoisted(() => [] as Array<{ query: Record<string, string> }>);
+
+vi.mock("@/state/store", async (importOriginal) => {
+ const original = await importOriginal<typeof import("@/state/store")>();
+ const config = { ...original.initialState.config, browserEngine: { kind: "engine", engine: "chrome", desktopView: true } };
+ return { ...original, useStore: () => ({ state: { ...original.initialState, config }, dispatch: vi.fn() }) };
+});
+vi.mock("@/lib/page-visible", () => ({ usePageVisible: () => true }));
+vi.mock("@/lib/browser-pip", () => ({ supportsBrowserPictureInPicture: () => false, useBrowserPictureInPicture: () => "" }));
+vi.mock("@/lib/browser-stream-client", async (importOriginal) => ({
+ ...await importOriginal<typeof import("@/lib/browser-stream-client")>(),
+ createPreviewStreamClient: (options: { access: { query: Record<string, string> } }) => { streams.push({ query: options.access.query }); return { send: () => {}, stop: () => {} }; },
+}));
+vi.mock("./browser/StreamSurface", () => ({
+ StreamSurface: (props: SurfaceProps) => { surfaces.push(props); return createElement("div", { "data-stub-surface": "" }); },
+}));
+vi.mock("./browser/BrowserDesktop", () => ({ BrowserDesktop: () => createElement("div", { "data-stub-desktop": "" }) }));
+vi.mock("./browser/BrowserProfilesManager", () => ({ BrowserProfilesManager: () => null }));
+vi.mock("./browser/MoreMenu", () => ({ MoreMenu: () => null }));
+vi.mock("./browser/PasskeyNotice", () => ({ PasskeyNotice: () => null }));
+
+const { LiveBrowser } = await import("./BrowserPanel");
+
+const bot: Bot = {
+ id: "scout", threadId: "thread-scout", name: "Scout", title: "Researcher", description: "", soul: "",
+ notifications: true, color: "green", unread: false, messages: [],
+ modelSelection: { instanceId: "claude", model: "claude-opus-5-5" },
+};
+
+let host: HTMLDivElement;
+let root: Root;
+beforeEach(() => {
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ surfaces.length = 0;
+ streams.length = 0;
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+ flushSync(() => root.render(createElement(LiveBrowser, { bot })));
+});
+afterEach(() => {
+ flushSync(() => root.unmount());
+ host.remove();
+ vi.unstubAllGlobals();
+});
+
+describe("the browser panel on a Cloud that shows the browser's window", () => {
+ it("streams without pictures and shows the desktop view once the browser runs, with no first frame ever", async () => {
+ const surface = surfaces.at(-1)!;
+ surface.connect({ width: 800, height: 600 }, {});
+ expect(streams.at(-1)!.query).toMatchObject({ frames: "0" });
+ await act(async () => {
+ surface.onConnectedChange?.(true);
+ surface.onMessage?.({ type: "starting" });
+ });
+ expect(host.querySelector("[data-stub-desktop]")).toBeNull();
+ await act(async () => {
+ surface.onControl?.({ controller: "unclaimed", canOperate: true, held: false, owned: false, controlling: false, stale: false, generation: 0, dialog: null });
+ surface.onMessage?.({ type: "tabs", tabs: [{ tabId: "t1", title: "Example", url: "https://example.com/", active: true }] });
+ });
+ expect(host.querySelector("[data-stub-desktop]")).not.toBeNull();
+ });
+});
diff --git a/src/components/BrowserPanel.tsx b/src/components/BrowserPanel.tsx
index 96c07296f4..ed0517d647 100644
--- a/src/components/BrowserPanel.tsx
+++ b/src/components/BrowserPanel.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useRef, useState } from "react";
+import { lazy, Suspense, useCallback, useEffect, useRef, useState } from "react";
import { Globe, Hand, Loader2, LockKeyhole, Moon, X } from "lucide-react";
import { browserUnavailableReason } from "@/lib/feature-flags";
import { t } from "@/lib/i18n";
@@ -20,6 +20,8 @@ import { passkeyWallAt } from "../../shared/passkey-wall";
import { browserScope, withBrowserScope } from "@/lib/team-browser";
import { useNativeViewObscured } from "@/lib/native-view-obscured";
+const BrowserDesktop = lazy(() => import("./browser/BrowserDesktop").then((module) => ({ default: module.BrowserDesktop })));
+
const button = "rounded-md p-1.5 text-ink-secondary hover:bg-inset hover:text-ink disabled:opacity-40 disabled:cursor-not-allowed";
const NO_NAV: BrowserNav = { url: "", loading: false, canGoBack: false, canGoForward: false };
@@ -43,6 +45,14 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
const { state } = useStore();
const [fallback, setFallback] = useState(false);
const stream = state.config?.browserEngine?.engine === "chrome" && !fallback;
+ const [noDesktop, setNoDesktop] = useState(false);
+ const desktopView = stream && state.config?.browserEngine?.desktopView === true && !noDesktop;
+ // The desktop app shows this browser natively over the page area; the stream underneath shows through any overlay.
+ const paneMode = stream && state.config?.browserEngine?.pane === true && Boolean(window.ogb?.browserPane);
+ // The page shows as a remote desktop or a native pane, not from the stream's pictures: the stream's tab list, which comes
+ // once the browser runs, ends the starting state rather than a first picture.
+ const pageNotFromFrames = useRef(false);
+ pageNotFromFrames.current = desktopView || paneMode;
const [attempt, setAttempt] = useState(0);
const [connected, setConnected] = useState(false);
const [control, setControl] = useState<PreviewStreamControl | null>(null);
@@ -102,7 +112,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
setAttempt((value) => value + 1);
}, []);
// Another profile may run on the other engine: it gets the stream again if it has one.
- useEffect(() => { setFallback(false); }, [bot.id, bot.browserProfile, scopedThread]);
+ useEffect(() => { setFallback(false); setNoDesktop(false); }, [bot.id, bot.browserProfile, scopedThread]);
useEffect(() => {
setTabs([]);
setExtensions(null);
@@ -116,14 +126,15 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
const connect = useCallback<SurfaceConnect>((target, events) => {
const scope: Record<string, string> = scopedThread ? { threadId: scopedThread } : {};
- if (stream) return createPreviewStreamClient({ access: browserStreamAccess(bot.id, window.location, scope), ...target }, events);
+ // The desktop view shows the page, so the stream beside it carries no pictures.
+ if (stream) return createPreviewStreamClient({ access: browserStreamAccess(bot.id, window.location, desktopView ? { ...scope, frames: "0" } : scope), ...target }, events);
const key = `${bot.id}\n${bot.browserProfile ?? ""}${scopedThread ? `\n${scopedThread}` : ""}`;
if (resume.current.key !== key) resume.current = { key, viewer: "" };
return createLiveStreamClient(bot.id, events, (body, viewerId) => api(withBrowserScope(`/api/bots/${encodeURIComponent(bot.id)}/browser/action`, scope), {
// 120 s matches the server's browser requestTimeoutMs.
method: "POST", body: JSON.stringify({ ...body, viewerId }), timeoutMs: 120_000,
}), resume.current, scope, { width: target.width, height: target.height });
- }, [bot.id, bot.browserProfile, scopedThread, stream]);
+ }, [bot.id, bot.browserProfile, scopedThread, stream, desktopView]);
const interact = useCallback((input: PreviewStreamInput) => {
if (controlRef.current?.controller === "another-viewer") {
@@ -170,6 +181,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
if (message.type === "tabs") {
const next = tabsOf(message.tabs);
setTabs(next);
+ if (pageNotFromFrames.current) setStarting(false);
const active = next.find((tab) => tab.active);
if (active) {
setNav((current) => ({ ...current, url: active.url }));
@@ -290,8 +302,6 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
setError("");
}, [shown]);
const typingReady = connected && you;
- // The desktop app shows this browser natively over the page area; the stream underneath shows through any overlay.
- const paneMode = stream && state.config?.browserEngine?.pane === true && Boolean(window.ogb?.browserPane);
const obscured = useNativeViewObscured(showProfiles || showTyping, paneMode);
const paneVisible = paneMode && shown && connected && !asleep && !heldElsewhere && !gone && !starting && !obscured;
const paneShown = useRef(paneVisible);
@@ -376,7 +386,7 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
<div ref={pageArea} {...(paneMode ? { "data-native-view-host": "" } : {})} className="relative flex min-h-0 flex-1 flex-col bg-inset/40">
{shown ? (
<StreamSurface
- key={`${attempt}:${stream ? "stream" : "live"}:${bot.browserProfile ?? ""}`}
+ key={`${attempt}:${stream ? "stream" : "live"}:${bot.browserProfile ?? ""}${desktopView ? ":desktop" : ""}`}
ref={surface}
connect={connect}
input={interact}
@@ -392,6 +402,18 @@ export function LiveBrowser({ bot, signIn, page }: { bot: Bot; signIn?: BrowserS
onLeave={() => address.current?.focus()}
/>
) : null}
+ {shown && desktopView && connected && !starting && !asleep && !gone && !heldElsewhere ? (
+ <Suspense fallback={null}>
+ <BrowserDesktop
+ key={`${attempt}:${bot.browserProfile ?? ""}`}
+ botId={bot.id}
+ scope={scopedThread ? { threadId: scopedThread } : {}}
+ controlling={you}
+ label={t("browser.panel.pageLabel", { name: bot.name })}
+ onUnavailable={() => setNoDesktop(true)}
+ />
+ </Suspense>
+ ) : null}
{asleep || heldElsewhere || gone || !connected || starting ? (
<div className="absolute inset-0 z-10 flex flex-col items-center justify-center gap-3 bg-card/95 p-6 text-center text-[13px] text-ink-secondary">
{asleep ? <Moon size={24} /> : heldElsewhere ? <Hand size={24} /> : gone ? <Globe size={24} /> : <Loader2 size={24} className="animate-spin" />}
diff --git a/src/components/browser/BrowserDesktop.dom.test.ts b/src/components/browser/BrowserDesktop.dom.test.ts
new file mode 100644
index 0000000000..76bb6e383d
--- /dev/null
+++ b/src/components/browser/BrowserDesktop.dom.test.ts
@@ -0,0 +1,128 @@
+// @vitest-environment happy-dom
+// The browser's window on a Cloud's private display: one noVNC client on the desktop route, view-only unless the person
+// holds the browser, and the picture view kept where the browser runs without a display.
+import { act, createElement } from "react";
+import { flushSync } from "react-dom";
+import { createRoot, type Root } from "react-dom/client";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+const opened = vi.hoisted(() => [] as Array<{ socket: { url: string; binaryType: string; close(code: number): void }; client: { viewOnly: boolean; resizeSession: boolean; focusOnClick: boolean; disconnected: number; focused: number; keys: unknown[][]; typed: string[] } }>);
+vi.mock("@/lib/desktop-connection", () => ({
+ socketUrl: (path: string) => `ws://app.test${path}`,
+ openDesktop: (_screen: HTMLElement, socket: never) => {
+ const client = { viewOnly: false, resizeSession: false, focusOnClick: true, disconnected: 0, focused: 0, keys: [] as unknown[][], typed: [] as string[], disconnect() { this.disconnected++; }, focus() { this.focused++; }, sendKey(...args: unknown[]) { this.keys.push(args); } };
+ opened.push({ socket, client });
+ return client;
+ },
+ typeOnDesktop: (client: { typed: string[] }, text: string) => { client.typed.push(text); },
+}));
+
+class FakeSocket extends EventTarget {
+ binaryType = "blob";
+ readonly url: string;
+ constructor(url: string) {
+ super();
+ this.url = url;
+ }
+ close(code: number): void {
+ this.dispatchEvent(Object.assign(new Event("close"), { code }));
+ }
+}
+
+const { BrowserDesktop, DESKTOP_VIEW_CLOSE } = await import("./BrowserDesktop");
+
+let host: HTMLDivElement;
+let root: Root;
+beforeEach(() => {
+ vi.useFakeTimers();
+ vi.stubGlobal("WebSocket", FakeSocket);
+ vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
+ opened.length = 0;
+ host = document.createElement("div");
+ document.body.append(host);
+ root = createRoot(host);
+});
+afterEach(() => {
+ flushSync(() => root.unmount());
+ host.remove();
+ vi.unstubAllGlobals();
+ vi.useRealTimers();
+});
+
+const render = (props: { controlling: boolean; onUnavailable?: () => void; scope?: Record<string, string>; pill?: boolean }) => flushSync(() => root.render(createElement(BrowserDesktop, {
+ botId: "scout", scope: props.scope ?? {}, controlling: props.controlling, label: "Scout's page", onUnavailable: props.onUnavailable ?? (() => {}),
+}, props.pill ? createElement("div", { "data-pill": "" }) : null)));
+
+/** What a phone keyboard does to the hidden field: the field's whole new value, then an input event. */
+const typeInto = (field: HTMLTextAreaElement, value: string) => {
+ field.value = value;
+ field.dispatchEvent(new Event("input", { bubbles: true }));
+};
+
+describe("the browser desktop view", () => {
+ it("opens the desktop route of the conversation's browser, view-only while the person watches", () => {
+ render({ controlling: false, scope: { threadId: "room-1" } });
+ expect(opened).toHaveLength(1);
+ expect(opened[0]!.socket.url).toBe("ws://app.test/api/bots/scout/browser/desktop?threadId=room-1");
+ expect(opened[0]!.socket.binaryType).toBe("arraybuffer");
+ expect(opened[0]!.client.viewOnly).toBe(true);
+ expect(host.querySelector("[data-browser-desktop]")?.getAttribute("aria-label")).toBe("Scout's page");
+ });
+
+ it("drives once the person holds the browser, and stops when they hand it back", () => {
+ render({ controlling: false });
+ expect(opened[0]!.client.resizeSession).toBe(false);
+ render({ controlling: true });
+ expect(opened[0]!.client.viewOnly).toBe(false);
+ expect(opened[0]!.client.resizeSession).toBe(true);
+ expect(opened[0]!.client.focused).toBe(1);
+ render({ controlling: false });
+ expect(opened[0]!.client.viewOnly).toBe(true);
+ expect(opened).toHaveLength(1);
+ });
+
+ it("opens the phone's keyboard on a tap while the person holds the browser, and sends what they type as keys", () => {
+ render({ controlling: false });
+ const screen = host.querySelector<HTMLElement>("[data-browser-desktop]")!;
+ const field = host.querySelector<HTMLTextAreaElement>("textarea")!;
+ screen.dispatchEvent(Object.assign(new Event("pointerdown", { bubbles: true }), { pointerType: "touch" }));
+ expect(document.activeElement).not.toBe(field);
+ render({ controlling: true });
+ screen.dispatchEvent(Object.assign(new Event("pointerdown", { bubbles: true }), { pointerType: "touch" }));
+ expect(document.activeElement).toBe(field);
+ expect(opened[0]!.client.focusOnClick).toBe(false);
+ typeInto(field, "\u200bhé😀");
+ typeInto(field, "\u200bok\nnext");
+ typeInto(field, "");
+ const client = opened[0]!.client;
+ expect(client.typed).toEqual(["hé😀", "ok", "next"]);
+ expect(client.keys).toEqual([[0xff0d, "Enter"], [0xff08, "Backspace"]]);
+ expect(field.value).toBe("\u200b");
+ field.blur();
+ expect(opened[0]!.client.focusOnClick).toBe(true);
+ });
+
+ it("keeps what is typed from a watcher's keyboard off the browser", () => {
+ render({ controlling: false });
+ typeInto(host.querySelector<HTMLTextAreaElement>("textarea")!, "\u200bsecret");
+ expect(opened[0]!.client.typed).toEqual([]);
+ });
+
+ it("shows what sits over the picture, such as the handoff pill", () => {
+ render({ controlling: false, pill: true });
+ expect(host.querySelector("[data-browser-desktop-view] [data-pill]")).not.toBeNull();
+ });
+
+ it("gives way to the picture view where the browser has no display, and reconnects after any other close", async () => {
+ const unavailable = vi.fn();
+ render({ controlling: false, onUnavailable: unavailable });
+ opened[0]!.socket.close(DESKTOP_VIEW_CLOSE.heldElsewhere);
+ await act(async () => { vi.advanceTimersByTime(2_000); });
+ expect(opened).toHaveLength(2);
+ expect(opened[0]!.client.disconnected).toBe(1);
+ opened[1]!.socket.close(DESKTOP_VIEW_CLOSE.pictures);
+ expect(unavailable).toHaveBeenCalledOnce();
+ await act(async () => { vi.advanceTimersByTime(10_000); });
+ expect(opened).toHaveLength(2);
+ });
+});
diff --git a/src/components/browser/BrowserDesktop.tsx b/src/components/browser/BrowserDesktop.tsx
new file mode 100644
index 0000000000..a1f2742df7
--- /dev/null
+++ b/src/components/browser/BrowserDesktop.tsx
@@ -0,0 +1,127 @@
+import { useEffect, useRef, useState, type ReactNode } from "react";
+import type RFB from "@novnc/novnc";
+import { openDesktop, socketUrl, typeOnDesktop } from "@/lib/desktop-connection";
+import { t } from "@/lib/i18n";
+import { withBrowserScope } from "@/lib/team-browser";
+
+/** The server's close codes for this view (server/browser/desktop/views.ts): the browser runs without a display, or
+ * another person holds it. */
+export const DESKTOP_VIEW_CLOSE = { pictures: 4415, heldElsewhere: 4409 } as const;
+const RETRY_MS = 2_000;
+/** Kept in the hidden text field: a phone keyboard's delete sends no key event, only removes a character the field sees go. */
+const SENTINEL = "​";
+const XK_BACKSPACE = 0xff08;
+const XK_RETURN = 0xff0d;
+
+/**
+ * A bot's browser window on its Cloud's private display, drawn over the picture view in the same rectangle. The v2
+ * stream beside it keeps the hold, tabs and prompts; this view only shows the window and, while the person holds the
+ * browser, carries their pointer and keys and sizes the display to the view. The server drops their input otherwise,
+ * so view-only here is a courtesy. A tap from a touch screen opens the device's keyboard on a hidden field whose text
+ * goes on as keys, as the computer viewer's does. `children` sit over the picture, as the handoff pill does.
+ */
+export function BrowserDesktop({ botId, scope, controlling, label, onUnavailable, children }: {
+ botId: string;
+ scope: Readonly<Record<string, string>>;
+ controlling: boolean;
+ label: string;
+ /** This browser has no desktop view: the picture view stays. */
+ onUnavailable: () => void;
+ children?: ReactNode;
+}) {
+ const screen = useRef<HTMLDivElement>(null);
+ const keyboard = useRef<HTMLTextAreaElement>(null);
+ const rfb = useRef<RFB | null>(null);
+ const composing = useRef(false);
+ const [attempt, setAttempt] = useState(0);
+ const controllingNow = useRef(controlling);
+ controllingNow.current = controlling;
+ const unavailable = useRef(onUnavailable);
+ unavailable.current = onUnavailable;
+ const scopeKey = new URLSearchParams(scope).toString();
+
+ useEffect(() => {
+ const controller = new AbortController();
+ let retry: ReturnType<typeof setTimeout> | undefined;
+ const socket = new WebSocket(socketUrl(withBrowserScope(`/api/bots/${encodeURIComponent(botId)}/browser/desktop`, Object.fromEntries(new URLSearchParams(scopeKey)))));
+ socket.binaryType = "arraybuffer";
+ socket.addEventListener("close", (event) => {
+ if (controller.signal.aborted) return;
+ if (event.code === DESKTOP_VIEW_CLOSE.pictures) unavailable.current();
+ else retry = setTimeout(() => setAttempt((value) => value + 1), RETRY_MS);
+ });
+ const client = openDesktop(screen.current!, socket, { signal: controller.signal, events: { connected: () => {}, disconnected: () => {} } });
+ client.viewOnly = !controllingNow.current;
+ client.resizeSession = controllingNow.current;
+ rfb.current = client;
+ return () => {
+ controller.abort();
+ clearTimeout(retry);
+ client.disconnect();
+ if (rfb.current === client) rfb.current = null;
+ };
+ }, [botId, scopeKey, attempt]);
+
+ useEffect(() => {
+ const client = rfb.current;
+ if (!client) return;
+ client.viewOnly = !controlling;
+ client.resizeSession = controlling;
+ if (controlling) client.focus({ preventScroll: true });
+ }, [controlling, attempt]);
+
+ const reset = (field: HTMLTextAreaElement) => {
+ field.value = SENTINEL;
+ field.setSelectionRange(SENTINEL.length, SENTINEL.length);
+ };
+ const typed = (field: HTMLTextAreaElement) => {
+ const client = rfb.current;
+ const value = field.value;
+ reset(field);
+ if (!client || !controllingNow.current) return;
+ if (!value.startsWith(SENTINEL)) {
+ client.sendKey(XK_BACKSPACE, "Backspace");
+ return;
+ }
+ const text = value.slice(SENTINEL.length);
+ if (!text) return;
+ const lines = text.split("\n");
+ lines.forEach((line, index) => {
+ if (index > 0) client.sendKey(XK_RETURN, "Enter");
+ if (line) typeOnDesktop(client, line);
+ });
+ };
+
+ return (
+ <div className="absolute inset-0 overflow-hidden" data-browser-desktop-view>
+ <div
+ ref={screen}
+ data-browser-desktop
+ aria-label={label}
+ className="absolute inset-0"
+ onPointerDown={(event) => {
+ if (event.pointerType !== "touch" || !controllingNow.current) return;
+ // noVNC focuses its canvas on the tap that follows, which would close the keyboard just opened.
+ if (rfb.current) rfb.current.focusOnClick = false;
+ keyboard.current?.focus({ preventScroll: true });
+ }}
+ />
+ <textarea
+ ref={keyboard}
+ aria-label={t("browser.panel.typeTextField")}
+ defaultValue={SENTINEL}
+ autoCapitalize="off"
+ autoCorrect="off"
+ autoComplete="off"
+ spellCheck={false}
+ className="sr-only"
+ onFocus={(event) => reset(event.currentTarget)}
+ onBlur={() => { if (rfb.current) rfb.current.focusOnClick = true; }}
+ onCompositionStart={() => { composing.current = true; }}
+ onCompositionEnd={(event) => { composing.current = false; typed(event.currentTarget); }}
+ onInput={(event) => { if (!composing.current) typed(event.currentTarget); }}
+ />
+ {children}
+ </div>
+ );
+}
diff --git a/src/lib/desktop-connection.ts b/src/lib/desktop-connection.ts
index 68b904e503..8ac5a31753 100644
--- a/src/lib/desktop-connection.ts
+++ b/src/lib/desktop-connection.ts
@@ -39,10 +39,25 @@ export async function connectDesktop(screen: HTMLElement, target: string, option
if (!response.ok) throw new DesktopUnreachable();
const config = await response.json();
cancelled.throwIfAborted();
- const websocket = new URL(`${path}/websockify`, location.href);
+ return openDesktop(screen, socketUrl(`${path}/websockify`), { password: config.password ?? "", signal: cancelled, events });
+}
+
+/** A same-origin WebSocket address for `path`. */
+export function socketUrl(path: string): string {
+ const websocket = new URL(path, location.href);
websocket.protocol = location.protocol === "https:" ? "wss:" : "ws:";
- const client = new RFB(screen, websocket.href, {
- credentials: { password: config.password ?? "", username: "", target: "" },
+ return websocket.href;
+}
+
+/** The app's noVNC client on an RFB WebSocket the server proxies, scaled into `screen`, with the local paste shortcut
+ * carried over. A bot's computer and a bot's browser window on a Cloud both show through it. */
+export function openDesktop(screen: HTMLElement, socket: string | WebSocket, { password = "", signal: cancelled, events }: {
+ password?: string;
+ signal: AbortSignal;
+ events: DesktopConnectionEvents;
+}): RFB {
+ const client = new RFB(screen, socket, {
+ credentials: { password, username: "", target: "" },
});
client.scaleViewport = true;
client.background = "var(--color-inset)";
diff --git a/src/state/config-status.ts b/src/state/config-status.ts
index 0ab9ca5a7c..086edab907 100644
--- a/src/state/config-status.ts
+++ b/src/state/config-status.ts
@@ -225,6 +225,9 @@ export interface BrowserEngineSummary {
engine?: "agent-browser" | "chrome";
/** The desktop app shows the Chrome engine's browsers as panes the person uses directly (browserEngine.surface "pane"). */
pane?: true;
+ /** browserEngine.cloudDisplay is on and this server can run it: the panel shows the browser's window as a remote
+ * desktop (GET /api/bots/:id/browser/desktop), and falls back to the picture view when that closes with 4415. */
+ desktopView?: true;
/** Self-hosted servers only: whether bots' browsers may open this server's own sites and its local network
* (browserEngine.egress.localNetwork, off by default). Absent on the desktop and on MausBot Cloud. */
serverSites?: boolean;