Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): sharp built-in browser on scaled Linux desktops
Bugfixer 21e3b0aa26875
diff --git a/server/browser/display.test.ts b/server/browser/display.test.tsindex 39d1b1e5b1..c3b023c8db 100644--- a/server/browser/display.test.ts+++ b/server/browser/display.test.ts@@ -27,6 +27,21 @@ describe("the display a headless bot browser reports", () => {expect(await displayScreen("desktop", { platform: "linux", env: { DISPLAY: ":0", GDK_SCALE: "2" }, runCommand: answering(xrandr) })).toEqual({ width: 1920, height: 1080, deviceScaleFactor: 2 });});+ it("takes an X display's scale from Xft.dpi when GDK_SCALE is not set, as Cinnamon, GNOME and KDE set it", async () => {+ const xrandr = "Screen 0: minimum 8 x 8, current 3840 x 2160\nDP-1 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 600mm x 340mm\n";+ const desktop = (xrdb: string | Error) => async (file: string) => {+ if (file === "xrandr") return xrandr;+ if (xrdb instanceof Error) throw xrdb;+ return xrdb;+ };+ const linux = (xrdb: string | Error, env: NodeJS.ProcessEnv = { DISPLAY: ":0" }) => displayScreen("desktop", { platform: "linux", env, runCommand: desktop(xrdb) });+ expect(await linux("*customization:\t-color\nXft.dpi:\t192\nXft.antialias:\t1\n")).toEqual({ width: 1920, height: 1080, deviceScaleFactor: 2 });+ expect(await linux("Xft.dpi: 144\n")).toEqual({ width: 2560, height: 1440, deviceScaleFactor: 1.5 });+ expect(await linux("Xft.dpi:\t96\n")).toEqual({ width: 3840, height: 2160, deviceScaleFactor: 1 });+ expect(await linux("*customization:\t-color\n")).toEqual({ width: 3840, height: 2160, deviceScaleFactor: 1 });+ expect(await linux(new Error("no xrdb"))).toEqual({ width: 3840, height: 2160, deviceScaleFactor: 1 });+ });+it("is a declared 1920x1080 at 1x on a server or in a container, and when the desktop cannot be read", async () => {const never = async () => { throw new Error("should not run"); };expect(await displayScreen("server", { platform: "linux", env: {}, runCommand: never })).toEqual(SERVER_SCREEN);diff --git a/server/browser/display.ts b/server/browser/display.tsindex 03f818bd00..ae6cc23394 100644--- a/server/browser/display.ts+++ b/server/browser/display.ts@@ -24,6 +24,18 @@ export function parseDisplay(text: string): ScreenSpec | null {return { width: Number(match[1]), height: Number(match[2]), deviceScaleFactor: Math.round(scale * 100) / 100 };}+/** Cinnamon, GNOME and KDE set a HiDPI or fractional scale as Xft.dpi (96 being 1x), not GDK_SCALE; the app's own window+ * draws at that scale, so a page at 1x would look blurry in it. */+async function xftScale(runCommand: Run): Promise<number> {+ try {+ const dpi = Number(/^Xft\.dpi:\s*(\d+(?:\.\d+)?)\s*$/mu.exec(await runCommand("xrdb", ["-query"], 5_000))?.[1]);+ const scale = Math.round((dpi / 96) * 100) / 100;+ return scale > 1 && scale <= 4 ? scale : 1;+ } catch {+ return 1;+ }+}+export async function displayScreen(host: HostKind, { platform = process.platform, env = process.env, runCommand = run }: { platform?: NodeJS.Platform; env?: NodeJS.ProcessEnv; runCommand?: Run } = {}): Promise<ScreenSpec> {const named = parseDisplay(env.OMB_BROWSER_SCREEN?.trim() ?? "");if (named) return named;@@ -34,9 +46,9 @@ export async function displayScreen(host: HostKind, { platform = process.platforif (platform === "linux" && (env.DISPLAY || env.WAYLAND_DISPLAY)) {const lines = (await runCommand("xrandr", ["--current"], 5_000)).split("\n").filter((line) => / connected /u.test(line));const pixels = parseDisplay(lines.find((line) => / primary /u.test(line)) ?? lines[0] ?? "");- const scale = Number(env.GDK_SCALE);if (!pixels) return SERVER_SCREEN;- if (!(Number.isInteger(scale) && scale > 1 && scale <= 4)) return pixels;+ const gdkScale = Number(env.GDK_SCALE);+ const scale = Number.isInteger(gdkScale) && gdkScale > 1 && gdkScale <= 4 ? gdkScale : await xftScale(runCommand);return { width: Math.round(pixels.width / scale), height: Math.round(pixels.height / scale), deviceScaleFactor: scale };}} catch {}