Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

feat(browser): detect Chrome Beta on macOS (#2157)

tiammomo14bf09755fc8
diff --git a/packages/browser-control-runtime/src/__tests__/chrome-executable-discovery.test.ts b/packages/browser-control-runtime/src/__tests__/chrome-executable-discovery.test.ts
new file mode 100644
index 0000000000..8841de79c6
--- /dev/null
+++ b/packages/browser-control-runtime/src/__tests__/chrome-executable-discovery.test.ts
@@ -0,0 +1,73 @@
+import fs from 'node:fs';
+import os from 'node:os';
+import path from 'node:path';
+
+import { afterEach, describe, expect, it, vi } from 'vitest';
+
+import {
+ findChromeExecutableMac,
+ resolveGoogleChromeExecutableForPlatform,
+} from '../_generated/extension/src/browser/chrome.executables.js';
+
+const stablePath = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome';
+const bravePath = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser';
+const testHome = path.join(path.sep, 'Users', 'test');
+const betaPaths = [
+ '/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta',
+ path.join(
+ testHome,
+ 'Applications',
+ 'Google Chrome Beta.app',
+ 'Contents',
+ 'MacOS',
+ 'Google Chrome Beta',
+ ),
+];
+
+afterEach(() => {
+ vi.restoreAllMocks();
+});
+
+describe('macOS Chrome executable discovery', () => {
+ it.each(betaPaths)('detects Chrome Beta at %s', (betaPath) => {
+ vi.spyOn(os, 'homedir').mockReturnValue(testHome);
+ vi.spyOn(fs, 'existsSync').mockImplementation(
+ (candidate) => String(candidate) === betaPath,
+ );
+
+ expect(findChromeExecutableMac()).toEqual({
+ kind: 'chrome',
+ path: betaPath,
+ });
+ expect(resolveGoogleChromeExecutableForPlatform('darwin')).toEqual({
+ kind: 'chrome',
+ path: betaPath,
+ });
+ });
+
+ it('keeps stable Chrome ahead of Beta', () => {
+ vi.spyOn(os, 'homedir').mockReturnValue(testHome);
+ vi.spyOn(fs, 'existsSync').mockImplementation((candidate) =>
+ [stablePath, ...betaPaths].includes(String(candidate)),
+ );
+
+ expect(findChromeExecutableMac()).toEqual({ kind: 'chrome', path: stablePath });
+ expect(resolveGoogleChromeExecutableForPlatform('darwin')).toEqual({
+ kind: 'chrome',
+ path: stablePath,
+ });
+ });
+
+ it('keeps stable third-party browsers ahead of Beta', () => {
+ vi.spyOn(os, 'homedir').mockReturnValue(testHome);
+ vi.spyOn(fs, 'existsSync').mockImplementation((candidate) =>
+ [bravePath, ...betaPaths].includes(String(candidate)),
+ );
+
+ expect(findChromeExecutableMac()).toEqual({ kind: 'brave', path: bravePath });
+ expect(resolveGoogleChromeExecutableForPlatform('darwin')).toEqual({
+ kind: 'chrome',
+ path: betaPaths[0],
+ });
+ });
+});
diff --git a/packages/browser-control-runtime/src/_generated/extension/src/browser/chrome.executables.ts b/packages/browser-control-runtime/src/_generated/extension/src/browser/chrome.executables.ts
index 3bbd3bd6fc..f6543b0fbe 100644
--- a/packages/browser-control-runtime/src/_generated/extension/src/browser/chrome.executables.ts
+++ b/packages/browser-control-runtime/src/_generated/extension/src/browser/chrome.executables.ts
@@ -577,6 +577,17 @@ export function findChromeExecutableMac(): BrowserExecutable | null {
kind: "chromium",
path: path.join(os.homedir(), "Applications/Chromium.app/Contents/MacOS/Chromium"),
},
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ },
+ {
+ kind: "chrome",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ ),
+ },
{
kind: "canary",
path: "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
@@ -594,14 +605,37 @@ export function findChromeExecutableMac(): BrowserExecutable | null {
}
function findGoogleChromeExecutableMac(): BrowserExecutable | null {
- return findFirstChromeExecutable([
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
- path.join(os.homedir(), "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
- "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
- path.join(
- os.homedir(),
- "Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
- ),
+ return findFirstExecutable([
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
+ },
+ {
+ kind: "chrome",
+ path: path.join(os.homedir(), "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
+ },
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ },
+ {
+ kind: "chrome",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ ),
+ },
+ {
+ kind: "canary",
+ path: "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ },
+ {
+ kind: "canary",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ ),
+ },
]);
}
diff --git a/packages/browser-control-runtime/upstream/browser-runtime.lock.json b/packages/browser-control-runtime/upstream/browser-runtime.lock.json
index 46dabc1953..c4bc636f96 100644
--- a/packages/browser-control-runtime/upstream/browser-runtime.lock.json
+++ b/packages/browser-control-runtime/upstream/browser-runtime.lock.json
@@ -14,6 +14,14 @@
"Full extraction live: core + leaf SSRF/security + net-policy + normalization-core + fs-safe dist, with hand-written src/shim/* for the plugin-sdk surface."
],
"patches": [
+ {
+ "file": "extension/src/browser/chrome.executables.ts",
+ "desc": "detect macOS Google Chrome Beta after stable Chromium-family browsers"
+ },
+ {
+ "file": "extension/src/browser/chrome.executables.ts",
+ "desc": "classify macOS Google Chrome Beta within the Chrome-only fallback"
+ },
{
"file": "extension/src/browser/config.ts",
"desc": "preserve narrow fake-IP SSRF allowances from the host config without enabling general private-network access"
@@ -24,7 +32,7 @@
}
],
"fileCount": 335,
- "contentHash": "1bc2c6ddddf76824846b6e14ce5bf27e3b222b3283c9fbf2beda1d4283d3040a",
+ "contentHash": "ec71c1f65b7239df32b0e861d8ac55a1dc55747487dae4fcf1ea4d16002c02ec",
"fsSafe": {
"package": "@openclaw/fs-safe",
"version": "0.4.0"
diff --git a/scripts/browser-runtime/sync.mjs b/scripts/browser-runtime/sync.mjs
index d573079047..610dfce86d 100644
--- a/scripts/browser-runtime/sync.mjs
+++ b/scripts/browser-runtime/sync.mjs
@@ -248,6 +248,82 @@ function header(srcLabel) {
* src/shim/* for anything that can live at the adapter boundary.
*/
const LOCAL_PATCHES = {
+ 'extension/src/browser/chrome.executables.ts': [
+ {
+ desc: 'detect macOS Google Chrome Beta after stable Chromium-family browsers',
+ find: ` {
+ kind: "chromium",
+ path: path.join(os.homedir(), "Applications/Chromium.app/Contents/MacOS/Chromium"),
+ },
+ {
+ kind: "canary",`,
+ replace: ` {
+ kind: "chromium",
+ path: path.join(os.homedir(), "Applications/Chromium.app/Contents/MacOS/Chromium"),
+ },
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ },
+ {
+ kind: "chrome",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ ),
+ },
+ {
+ kind: "canary",`,
+ },
+ {
+ desc: 'classify macOS Google Chrome Beta within the Chrome-only fallback',
+ find: `function findGoogleChromeExecutableMac(): BrowserExecutable | null {
+ return findFirstChromeExecutable([
+ "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
+ path.join(os.homedir(), "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
+ "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ path.join(
+ os.homedir(),
+ "Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ ),
+ ]);
+}`,
+ replace: `function findGoogleChromeExecutableMac(): BrowserExecutable | null {
+ return findFirstExecutable([
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
+ },
+ {
+ kind: "chrome",
+ path: path.join(os.homedir(), "Applications/Google Chrome.app/Contents/MacOS/Google Chrome"),
+ },
+ {
+ kind: "chrome",
+ path: "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ },
+ {
+ kind: "chrome",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta",
+ ),
+ },
+ {
+ kind: "canary",
+ path: "/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ },
+ {
+ kind: "canary",
+ path: path.join(
+ os.homedir(),
+ "Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary",
+ ),
+ },
+ ]);
+}`,
+ },
+ ],
'extension/src/browser/config.ts': [
{
desc: 'preserve narrow fake-IP SSRF allowances from the host config without enabling general private-network access',