Skip to content

Commit 967f56e

Browse files
committed
Add Gemini computer use support (Fixes #148)
1 parent d0a27ab commit 967f56e

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

packages/browseros/chromium_patches/chrome/browser/resources/settings/nxtscape_page/models_data.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ index 0000000000000..36638c1910a09
88
+export interface ModelInfo {
99
+ model_id: string;
1010
+ context_length: number;
11+
+ requires_computer_use?: boolean;
1112
+}
1213
+
1314
+export interface ModelsData {
@@ -66,6 +67,7 @@ index 0000000000000..36638c1910a09
6667
+ { model_id: 'gemini-2.5-pro-preview-05-06', context_length: 1048576 },
6768
+ { model_id: 'gemini-2.5-pro-preview-06-05', context_length: 1048576 },
6869
+ { model_id: 'gemini-2.5-pro', context_length: 1048576 },
70+
+ { model_id: 'gemini-2.5-computer-use-preview-10-2025', context_length: 1048576, requires_computer_use: true },
6971
+ { model_id: 'gemini-2.0-flash-exp', context_length: 1048576 },
7072
+ { model_id: 'gemini-2.0-flash', context_length: 1048576 },
7173
+ { model_id: 'gemini-2.0-flash-001', context_length: 1048576 },
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
importScripts("computer_use_patch.js");
2+
importScripts("background.js");
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
(() => {
2+
const existing = globalThis.fetch;
3+
if (!existing || existing.__browserosComputerUsePatched) return;
4+
5+
const originalFetch = existing.bind(globalThis);
6+
const computerUseModels = new Set(["gemini-2.5-computer-use-preview-10-2025"]);
7+
8+
const normalizePayload = (payload) => {
9+
if (!payload || typeof payload !== "object") return null;
10+
if (!computerUseModels.has(payload.model)) return null;
11+
12+
const tools = Array.isArray(payload.tools) ? payload.tools.slice() : [];
13+
const hasTool = tools.some((tool) => tool && typeof tool === "object" && "computer_use" in tool);
14+
15+
if (!hasTool) {
16+
tools.push({ computer_use: { environment: "ENVIRONMENT_BROWSER" } });
17+
payload.tools = tools;
18+
return payload;
19+
}
20+
21+
return payload;
22+
};
23+
24+
const updateInit = (init) => {
25+
if (!init || typeof init !== "object") return null;
26+
if (!init.body) return null;
27+
28+
if (typeof init.body === "string") {
29+
try {
30+
const payload = JSON.parse(init.body);
31+
const updated = normalizePayload(payload);
32+
if (updated) {
33+
return { ...init, body: JSON.stringify(updated) };
34+
}
35+
} catch {
36+
return null;
37+
}
38+
} else if (typeof init.body === "object") {
39+
const updated = normalizePayload(init.body);
40+
if (updated) {
41+
return { ...init, body: JSON.stringify(updated) };
42+
}
43+
}
44+
45+
return null;
46+
};
47+
48+
const wrappedFetch = (...args) => {
49+
const [input, init] = args;
50+
const nextInit = updateInit(init);
51+
52+
if (nextInit) {
53+
return originalFetch(input, nextInit);
54+
}
55+
56+
return originalFetch(...args);
57+
};
58+
59+
wrappedFetch.__browserosComputerUsePatched = true;
60+
globalThis.fetch = wrappedFetch;
61+
})();

packages/browseros/resources/files/ai_side_panel/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"<all_urls>"
2222
],
2323
"background": {
24-
"service_worker": "background.js"
24+
"service_worker": "background_wrapper.js"
2525
},
2626
"action": {
2727
"default_icon": {
@@ -60,4 +60,4 @@
6060
"128": "assets/icon128.png"
6161
},
6262
"component": true
63-
}
63+
}

0 commit comments

Comments
 (0)