Skip to content

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

fix(browser): round scaled-display DIPs so Windows screen size is not read as 66667x1066

koeria7a501740e198
diff --git a/server/browser/chrome/wrapper.test.ts b/server/browser/chrome/wrapper.test.ts
index cdcc524bdb..2a9a098355 100644
--- a/server/browser/chrome/wrapper.test.ts
+++ b/server/browser/chrome/wrapper.test.ts
@@ -118,6 +118,8 @@ describe("the display, language and time zone the launcher gives Chrome", () =>
it("reads the primary display on each desktop, and declares 1920x1080 where there is none", async () => {
expect(await primaryScreen("darwin", {}, answer("1512x982\n"))).toEqual({ width: 1512, height: 982 });
expect(await primaryScreen("win32", {}, answer("1536x864\r\n"))).toEqual({ width: 1536, height: 864 });
+ // A scaled display (150%) reports fractional DIPs; reading only the tail digits turned 1706.66… into 66667.
+ expect(await primaryScreen("win32", {}, answer("1706.66666666667x1066.66666666667"))).toEqual({ width: 1707, height: 1067 });
const xrandr = "Screen 0: minimum 8 x 8, current 4480 x 1440\nHDMI-1 connected 2560x1440+1920+0 (normal) 597mm x 336mm\neDP-1 connected primary 1920x1080+0+0 (normal) 344mm x 194mm\n";
expect(await primaryScreen("linux", { DISPLAY: ":0" }, answer(xrandr))).toEqual({ width: 1920, height: 1080 });
expect(await primaryScreen("linux", {}, answer(xrandr))).toEqual({ width: 1920, height: 1080 });
diff --git a/server/browser/chrome/wrapper.ts b/server/browser/chrome/wrapper.ts
index c0e3b97d09..ba0e171733 100644
--- a/server/browser/chrome/wrapper.ts
+++ b/server/browser/chrome/wrapper.ts
@@ -108,17 +108,18 @@ const run: Run = (file, args, timeoutMs) => new Promise((resolve, reject) => {
execFile(file, args, { encoding: "utf8", timeout: timeoutMs, windowsHide: true }, (error, stdout) => error ? reject(error) : resolve(String(stdout)));
});
-const SIZE = /(\d{3,5})x(\d{3,5})/u;
+const SIZE = /(\d{3,5}(?:\.\d+)?)x(\d{3,5}(?:\.\d+)?)/u;
const SERVER_SCREEN: Screen = { width: 1920, height: 1080 };
const MAC_SCREEN = `ObjC.import("AppKit"); const size = $.NSScreen.screens.objectAtIndex(0).frame.size; Math.round(size.width) + "x" + Math.round(size.height)`;
-/** WPF reports the primary screen in device-independent pixels, the unit of a page's `screen.width`. */
-const WINDOWS_SCREEN = "Add-Type -AssemblyName PresentationFramework; '{0}x{1}' -f [System.Windows.SystemParameters]::PrimaryScreenWidth, [System.Windows.SystemParameters]::PrimaryScreenHeight";
+/** WPF reports the primary screen in device-independent pixels, the unit of a page's `screen.width`. F0 rounds away the
+ * fractional DIPs of a scaled display (150% gives 1706.666…), which a coarse scan would otherwise read as 66667. */
+const WINDOWS_SCREEN = "Add-Type -AssemblyName PresentationFramework; '{0:F0}x{1:F0}' -f [System.Windows.SystemParameters]::PrimaryScreenWidth, [System.Windows.SystemParameters]::PrimaryScreenHeight";
/** The primary display, as headed Chrome reports `screen` on it; a server has none and declares 1920×1080. */
export async function primaryScreen(platform: NodeJS.Platform, env: NodeJS.ProcessEnv, runCommand: Run = run): Promise<Screen> {
const parse = (output: string): Screen | null => {
const match = SIZE.exec(output);
- return match ? { width: Number(match[1]), height: Number(match[2]) } : null;
+ return match ? { width: Math.round(Number(match[1])), height: Math.round(Number(match[2])) } : null;
};
const named = parse(env.OMB_BROWSER_SCREEN?.trim() ?? "");
if (named) return named;