Skip to content

Commit a68f25d

Browse files
committed
fix(browser): avoid cold mac chrome version timeouts
1 parent 32f9150 commit a68f25d

3 files changed

Lines changed: 119 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ Docs: https://docs.openclaw.ai
137137
- CLI/agents: default new omitted-account bindings to all accounts when the channel has multiple configured accounts, and clarify account-scope docs. (#49769) Thanks @Gcaufy.
138138
- Codex app-server: let authorized `/codex` control commands such as `/codex detach` escape plugin-owned conversation bindings while keeping unknown or unauthorized slash text routed to the bound plugin. Fixes #85157. (#85188) Thanks @TurboTheTurtle.
139139
- Auto-reply/models: keep `/models` browse replies fast by sharing the bounded read-only catalog path with Gateway model listing. (#84735) Thanks @safrano9999.
140+
- Browser/Doctor: read macOS Chrome app bundle versions from `Info.plist` before spawning Chrome and extend the fallback version probe timeout, avoiding false cold-cache warnings from Gatekeeper latency. Fixes #85418. Thanks @davidcittadini.
140141
- Codex app-server: disable native Code Mode when the effective exec host is `node` and keep OpenClaw `exec`/`process` available, so `/exec host=node` routes shell commands through the selected node instead of the gateway. Fixes #85012. (#85090) Thanks @sahilsatralkar.
141142
- Agents: bound embedded auto-compaction session write-lock watchdogs to the compaction timeout instead of the full run timeout, so stuck compaction cannot hold the live session lock for the whole run window. (#84949) Thanks @luoyanglang.
142143
- Gateway/agents: return phase-aware `agent.wait` timeout attribution and only cool auth profiles on provider-started timeouts. Refs #65504. Thanks @100yenadmin.

‎extensions/browser/src/browser/chrome.executables.ts‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export type BrowserExecutable = {
1515

1616
const CHROME_VERSION_RE = /\b(\d+)(?:\.\d+){1,3}\b/g;
1717
const PLAYWRIGHT_BROWSERS_PATH_ENV = "PLAYWRIGHT_BROWSERS_PATH";
18+
const BROWSER_VERSION_TIMEOUT_MS = 6000;
19+
const MAC_PLISTBUDDY_TIMEOUT_MS = 800;
1820

1921
const CHROMIUM_BUNDLE_IDS = new Set([
2022
"com.google.Chrome",
@@ -732,13 +734,42 @@ export function resolveGoogleChromeExecutableForPlatform(
732734
}
733735

734736
export function readBrowserVersion(executablePath: string): string | null {
735-
const output = execText(executablePath, ["--version"], 2000);
737+
if (process.platform === "darwin") {
738+
const bundleVersion = readMacBundleBrowserVersion(executablePath);
739+
if (bundleVersion) {
740+
return bundleVersion;
741+
}
742+
}
743+
744+
const output = execText(executablePath, ["--version"], BROWSER_VERSION_TIMEOUT_MS);
736745
if (!output) {
737746
return null;
738747
}
739748
return output.replace(/\s+/g, " ").trim();
740749
}
741750

751+
function readMacBundleBrowserVersion(executablePath: string): string | null {
752+
const appBundlePath = resolveMacAppBundlePath(executablePath);
753+
if (!appBundlePath) {
754+
return null;
755+
}
756+
const plistPath = path.join(appBundlePath, "Contents", "Info.plist");
757+
return execText(
758+
"/usr/libexec/PlistBuddy",
759+
["-c", "Print :CFBundleShortVersionString", plistPath],
760+
MAC_PLISTBUDDY_TIMEOUT_MS,
761+
);
762+
}
763+
764+
function resolveMacAppBundlePath(executablePath: string): string | null {
765+
const parts = path.normalize(executablePath).split(path.sep);
766+
const appIndex = parts.findIndex((part) => part.endsWith(".app"));
767+
if (appIndex < 0) {
768+
return null;
769+
}
770+
return parts.slice(0, appIndex + 1).join(path.sep) || path.sep;
771+
}
772+
742773
export function parseBrowserMajorVersion(rawVersion: string | null | undefined): number | null {
743774
const matches = [...(rawVersion ?? "").matchAll(CHROME_VERSION_RE)];
744775
const match = matches.at(-1);
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { afterEach, describe, expect, it, vi } from "vitest";
2+
3+
const execFileSyncMock = vi.hoisted(() => vi.fn());
4+
5+
vi.mock("node:child_process", async () => {
6+
const actual = await vi.importActual<typeof import("node:child_process")>("node:child_process");
7+
return {
8+
...actual,
9+
execFileSync: (...args: unknown[]) => execFileSyncMock(...args),
10+
};
11+
});
12+
13+
import { readBrowserVersion } from "./chrome.executables.js";
14+
15+
function stubPlatform(platform: NodeJS.Platform): void {
16+
Object.defineProperty(process, "platform", {
17+
configurable: true,
18+
value: platform,
19+
});
20+
}
21+
22+
describe("readBrowserVersion", () => {
23+
const originalPlatform = process.platform;
24+
25+
afterEach(() => {
26+
stubPlatform(originalPlatform);
27+
execFileSyncMock.mockReset();
28+
vi.restoreAllMocks();
29+
});
30+
31+
it("reads macOS app bundle versions from Info.plist before spawning Chrome", () => {
32+
stubPlatform("darwin");
33+
execFileSyncMock.mockReturnValue("148.0.7778.179\n");
34+
35+
const version = readBrowserVersion(
36+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
37+
);
38+
39+
expect(version).toBe("148.0.7778.179");
40+
expect(execFileSyncMock).toHaveBeenCalledTimes(1);
41+
expect(execFileSyncMock).toHaveBeenCalledWith(
42+
"/usr/libexec/PlistBuddy",
43+
[
44+
"-c",
45+
"Print :CFBundleShortVersionString",
46+
"/Applications/Google Chrome.app/Contents/Info.plist",
47+
],
48+
expect.objectContaining({ timeout: 800 }),
49+
);
50+
});
51+
52+
it("falls back to a slower --version probe when macOS bundle metadata is unavailable", () => {
53+
stubPlatform("darwin");
54+
execFileSyncMock
55+
.mockImplementationOnce(() => {
56+
throw new Error("plist unavailable");
57+
})
58+
.mockReturnValueOnce("Google Chrome 148.0.7778.179\n");
59+
60+
const version = readBrowserVersion(
61+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
62+
);
63+
64+
expect(version).toBe("Google Chrome 148.0.7778.179");
65+
expect(execFileSyncMock).toHaveBeenNthCalledWith(
66+
2,
67+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
68+
["--version"],
69+
expect.objectContaining({ timeout: 6000 }),
70+
);
71+
});
72+
73+
it("uses the slower --version probe for non-bundle paths", () => {
74+
stubPlatform("darwin");
75+
execFileSyncMock.mockReturnValue("Chromium 148.0.7778.179\n");
76+
77+
const version = readBrowserVersion("/opt/chromium/chrome");
78+
79+
expect(version).toBe("Chromium 148.0.7778.179");
80+
expect(execFileSyncMock).toHaveBeenCalledWith(
81+
"/opt/chromium/chrome",
82+
["--version"],
83+
expect.objectContaining({ timeout: 6000 }),
84+
);
85+
});
86+
});

0 commit comments

Comments
 (0)