@askjo/camofox-browser 1.8.11 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -25
- package/README.md +32 -28
- package/lib/config.js +2 -1
- package/lib/images.js +1 -1
- package/lib/launcher.js +1 -1
- package/lib/metrics.js +2 -2
- package/lib/reporter.js +71 -42
- package/lib/request-utils.js +4 -1
- package/lib/resources.js +1 -1
- package/openclaw.plugin.json +18 -18
- package/package.json +12 -4
- package/plugin.js +616 -0
- package/plugins/vnc/AGENTS.md +3 -3
- package/plugins/vnc/spawn.js +1 -1
- package/plugins/vnc/vnc-launcher.js +1 -1
- package/plugins/youtube/AGENTS.md +2 -2
- package/scripts/postinstall.js +61 -0
- package/server.js +286 -22
- package/tsconfig.json +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@askjo/camofox-browser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "Headless browser automation server and OpenClaw plugin for AI agents - anti-detection, element refs, and session isolation",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "server.js",
|
|
@@ -40,6 +40,8 @@
|
|
|
40
40
|
"plugins/",
|
|
41
41
|
"camofox.config.json",
|
|
42
42
|
"plugin.ts",
|
|
43
|
+
"plugin.js",
|
|
44
|
+
"tsconfig.json",
|
|
43
45
|
"openclaw.plugin.json",
|
|
44
46
|
"scripts/",
|
|
45
47
|
"run.sh",
|
|
@@ -52,11 +54,14 @@
|
|
|
52
54
|
"extensions": [
|
|
53
55
|
"plugin.ts"
|
|
54
56
|
],
|
|
57
|
+
"runtimeExtensions": [
|
|
58
|
+
"plugin.js"
|
|
59
|
+
],
|
|
55
60
|
"compat": {
|
|
56
61
|
"pluginApi": ">=2026.3.24-beta.2"
|
|
57
62
|
},
|
|
58
63
|
"build": {
|
|
59
|
-
"openclawVersion": "2026.
|
|
64
|
+
"openclawVersion": "2026.5.3"
|
|
60
65
|
},
|
|
61
66
|
"tools": [
|
|
62
67
|
{
|
|
@@ -102,6 +107,7 @@
|
|
|
102
107
|
]
|
|
103
108
|
},
|
|
104
109
|
"scripts": {
|
|
110
|
+
"build": "tsc -p . || true",
|
|
105
111
|
"start": "node server.js",
|
|
106
112
|
"test": "NODE_OPTIONS='--experimental-vm-modules' jest --runInBand --forceExit",
|
|
107
113
|
"test:e2e": "NODE_OPTIONS='--experimental-vm-modules' jest --runInBand --forceExit tests/e2e",
|
|
@@ -112,7 +118,7 @@
|
|
|
112
118
|
"generate-openapi": "node scripts/generate-openapi.js",
|
|
113
119
|
"version:sync": "node scripts/sync-version.js",
|
|
114
120
|
"version": "node scripts/sync-version.js && node scripts/generate-openapi.js && git add openclaw.plugin.json openapi.json",
|
|
115
|
-
"postinstall": "
|
|
121
|
+
"postinstall": "node scripts/postinstall.js"
|
|
116
122
|
},
|
|
117
123
|
"dependencies": {
|
|
118
124
|
"camoufox-js": "^0.8.5",
|
|
@@ -125,7 +131,9 @@
|
|
|
125
131
|
"swagger-jsdoc": "^6.2.8"
|
|
126
132
|
},
|
|
127
133
|
"devDependencies": {
|
|
134
|
+
"@types/node": "^22.0.0",
|
|
128
135
|
"jest": "^29.7.0",
|
|
129
|
-
"pngjs": "^7.0.0"
|
|
136
|
+
"pngjs": "^7.0.0",
|
|
137
|
+
"typescript": "^5.7.0"
|
|
130
138
|
}
|
|
131
139
|
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,616 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camoufox Browser - OpenClaw Plugin
|
|
3
|
+
*
|
|
4
|
+
* Provides browser automation tools using the Camoufox anti-detection browser.
|
|
5
|
+
* Server auto-starts when plugin loads (configurable via autoStart: false).
|
|
6
|
+
*/
|
|
7
|
+
import { dirname, resolve } from "path";
|
|
8
|
+
import { fileURLToPath } from "url";
|
|
9
|
+
import { randomUUID } from "crypto";
|
|
10
|
+
import { loadConfig } from "./lib/config.js";
|
|
11
|
+
import { launchServer } from "./lib/launcher.js";
|
|
12
|
+
import { readCookieFile } from "./lib/cookies.js";
|
|
13
|
+
// Get plugin directory - works in both ESM and CJS contexts
|
|
14
|
+
const getPluginDir = () => {
|
|
15
|
+
try {
|
|
16
|
+
// ESM context
|
|
17
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
// CJS context
|
|
21
|
+
return __dirname;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
let serverProcess = null;
|
|
25
|
+
async function startServer(pluginDir, port, log, pluginCfg) {
|
|
26
|
+
const cfg = loadConfig();
|
|
27
|
+
const env = { ...cfg.serverEnv };
|
|
28
|
+
if (pluginCfg?.maxSessions != null)
|
|
29
|
+
env.MAX_SESSIONS = String(pluginCfg.maxSessions);
|
|
30
|
+
if (pluginCfg?.maxTabsPerSession != null)
|
|
31
|
+
env.MAX_TABS_PER_SESSION = String(pluginCfg.maxTabsPerSession);
|
|
32
|
+
if (pluginCfg?.sessionTimeoutMs != null)
|
|
33
|
+
env.SESSION_TIMEOUT_MS = String(pluginCfg.sessionTimeoutMs);
|
|
34
|
+
if (pluginCfg?.browserIdleTimeoutMs != null)
|
|
35
|
+
env.BROWSER_IDLE_TIMEOUT_MS = String(pluginCfg.browserIdleTimeoutMs);
|
|
36
|
+
const proc = launchServer({ pluginDir, port, env, log, nodeArgs: pluginCfg?.maxOldSpaceSize != null ? [`--max-old-space-size=${pluginCfg.maxOldSpaceSize}`] : undefined });
|
|
37
|
+
proc.on("error", (err) => {
|
|
38
|
+
log?.error?.(`Server process error: ${err.message}`);
|
|
39
|
+
serverProcess = null;
|
|
40
|
+
});
|
|
41
|
+
proc.on("exit", (code) => {
|
|
42
|
+
if (code !== 0 && code !== null) {
|
|
43
|
+
log?.error?.(`Server exited with code ${code}`);
|
|
44
|
+
}
|
|
45
|
+
serverProcess = null;
|
|
46
|
+
});
|
|
47
|
+
// Wait for server to be ready
|
|
48
|
+
const baseUrl = `http://localhost:${port}`;
|
|
49
|
+
for (let i = 0; i < 30; i++) {
|
|
50
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
51
|
+
try {
|
|
52
|
+
const res = await fetch(`${baseUrl}/health`);
|
|
53
|
+
if (res.ok) {
|
|
54
|
+
log.info(`Camoufox server ready on port ${port}`);
|
|
55
|
+
return proc;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// Server not ready yet
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
proc.kill();
|
|
63
|
+
throw new Error("Server failed to start within 15 seconds");
|
|
64
|
+
}
|
|
65
|
+
async function checkServerRunning(baseUrl) {
|
|
66
|
+
try {
|
|
67
|
+
const res = await fetch(`${baseUrl}/health`);
|
|
68
|
+
return res.ok;
|
|
69
|
+
}
|
|
70
|
+
catch {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async function fetchApi(baseUrl, path, options = {}) {
|
|
75
|
+
const url = `${baseUrl}${path}`;
|
|
76
|
+
const res = await fetch(url, {
|
|
77
|
+
...options,
|
|
78
|
+
headers: {
|
|
79
|
+
"Content-Type": "application/json",
|
|
80
|
+
...options.headers,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
const text = await res.text();
|
|
85
|
+
throw new Error(`${res.status}: ${text}`);
|
|
86
|
+
}
|
|
87
|
+
return res.json();
|
|
88
|
+
}
|
|
89
|
+
function toToolResult(data) {
|
|
90
|
+
return {
|
|
91
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
export default function register(api) {
|
|
95
|
+
const cfg = api.pluginConfig ?? api.config;
|
|
96
|
+
const port = cfg.port || 9377;
|
|
97
|
+
const baseUrl = cfg.url || `http://localhost:${port}`;
|
|
98
|
+
const autoStart = cfg.autoStart !== false; // default true
|
|
99
|
+
const pluginDir = getPluginDir();
|
|
100
|
+
const fallbackUserId = `camofox-${randomUUID()}`;
|
|
101
|
+
// Auto-start server if configured (default: true)
|
|
102
|
+
if (autoStart) {
|
|
103
|
+
(async () => {
|
|
104
|
+
const alreadyRunning = await checkServerRunning(baseUrl);
|
|
105
|
+
if (alreadyRunning) {
|
|
106
|
+
api.log?.info?.(`Camoufox server already running at ${baseUrl}`);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
try {
|
|
110
|
+
serverProcess = await startServer(pluginDir, port, api.log, cfg);
|
|
111
|
+
}
|
|
112
|
+
catch (err) {
|
|
113
|
+
api.log?.error?.(`Failed to auto-start server: ${err.message}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
}
|
|
118
|
+
api.registerTool((ctx) => ({
|
|
119
|
+
name: "camofox_create_tab",
|
|
120
|
+
description: "PREFERRED: Create a new browser tab using Camoufox anti-detection browser. Use camofox tools instead of Chrome/built-in browser - they bypass bot detection on Google, Amazon, LinkedIn, etc. Returns tabId for subsequent operations.",
|
|
121
|
+
parameters: {
|
|
122
|
+
type: "object",
|
|
123
|
+
properties: {
|
|
124
|
+
url: { type: "string", description: "Initial URL to navigate to" },
|
|
125
|
+
},
|
|
126
|
+
required: ["url"],
|
|
127
|
+
},
|
|
128
|
+
async execute(_id, params) {
|
|
129
|
+
const sessionKey = ctx.sessionKey || "default";
|
|
130
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
131
|
+
const result = await fetchApi(baseUrl, "/tabs", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: JSON.stringify({ ...params, userId, sessionKey }),
|
|
134
|
+
});
|
|
135
|
+
return toToolResult(result);
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
api.registerTool((ctx) => ({
|
|
139
|
+
name: "camofox_snapshot",
|
|
140
|
+
description: "Get accessibility snapshot of a Camoufox page with element refs (e1, e2, etc.) for interaction, plus a visual screenshot. " +
|
|
141
|
+
"Large pages are truncated with pagination links preserved at the bottom. " +
|
|
142
|
+
"If the response includes hasMore=true and nextOffset, call again with that offset to see more content.",
|
|
143
|
+
parameters: {
|
|
144
|
+
type: "object",
|
|
145
|
+
properties: {
|
|
146
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
147
|
+
offset: { type: "number", description: "Character offset for paginated snapshots. Use nextOffset from a previous truncated response." },
|
|
148
|
+
},
|
|
149
|
+
required: ["tabId"],
|
|
150
|
+
},
|
|
151
|
+
async execute(_id, params) {
|
|
152
|
+
const { tabId, offset } = params;
|
|
153
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
154
|
+
const qs = offset ? `&offset=${offset}` : '';
|
|
155
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/snapshot?userId=${userId}&includeScreenshot=true${qs}`);
|
|
156
|
+
const content = [
|
|
157
|
+
{ type: "text", text: JSON.stringify({ url: result.url, refsCount: result.refsCount, snapshot: result.snapshot, truncated: result.truncated, totalChars: result.totalChars, hasMore: result.hasMore, nextOffset: result.nextOffset }, null, 2) },
|
|
158
|
+
];
|
|
159
|
+
const screenshot = result.screenshot;
|
|
160
|
+
if (screenshot?.data) {
|
|
161
|
+
content.push({ type: "image", data: screenshot.data, mimeType: screenshot.mimeType || "image/png" });
|
|
162
|
+
}
|
|
163
|
+
return { content };
|
|
164
|
+
},
|
|
165
|
+
}));
|
|
166
|
+
api.registerTool((ctx) => ({
|
|
167
|
+
name: "camofox_click",
|
|
168
|
+
description: "Click an element in a Camoufox tab by ref (e.g., e1) or CSS selector.",
|
|
169
|
+
parameters: {
|
|
170
|
+
type: "object",
|
|
171
|
+
properties: {
|
|
172
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
173
|
+
ref: { type: "string", description: "Element ref from snapshot (e.g., e1)" },
|
|
174
|
+
selector: { type: "string", description: "CSS selector (alternative to ref)" },
|
|
175
|
+
},
|
|
176
|
+
required: ["tabId"],
|
|
177
|
+
},
|
|
178
|
+
async execute(_id, params) {
|
|
179
|
+
const { tabId, ...rest } = params;
|
|
180
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
181
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/click`, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
184
|
+
});
|
|
185
|
+
return toToolResult(result);
|
|
186
|
+
},
|
|
187
|
+
}));
|
|
188
|
+
api.registerTool((ctx) => ({
|
|
189
|
+
name: "camofox_type",
|
|
190
|
+
description: "Type text into an element in a Camoufox tab.",
|
|
191
|
+
parameters: {
|
|
192
|
+
type: "object",
|
|
193
|
+
properties: {
|
|
194
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
195
|
+
ref: { type: "string", description: "Element ref from snapshot (e.g., e2)" },
|
|
196
|
+
selector: { type: "string", description: "CSS selector (alternative to ref)" },
|
|
197
|
+
text: { type: "string", description: "Text to type" },
|
|
198
|
+
pressEnter: { type: "boolean", description: "Press Enter after typing" },
|
|
199
|
+
},
|
|
200
|
+
required: ["tabId", "text"],
|
|
201
|
+
},
|
|
202
|
+
async execute(_id, params) {
|
|
203
|
+
const { tabId, ...rest } = params;
|
|
204
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
205
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/type`, {
|
|
206
|
+
method: "POST",
|
|
207
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
208
|
+
});
|
|
209
|
+
return toToolResult(result);
|
|
210
|
+
},
|
|
211
|
+
}));
|
|
212
|
+
api.registerTool((ctx) => ({
|
|
213
|
+
name: "camofox_navigate",
|
|
214
|
+
description: "Navigate a Camoufox tab to a URL or use a search macro (@google_search, @youtube_search, etc.). Preferred over Chrome for sites with bot detection.",
|
|
215
|
+
parameters: {
|
|
216
|
+
type: "object",
|
|
217
|
+
properties: {
|
|
218
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
219
|
+
url: { type: "string", description: "URL to navigate to" },
|
|
220
|
+
macro: {
|
|
221
|
+
type: "string",
|
|
222
|
+
description: "Search macro (e.g., @google_search, @youtube_search)",
|
|
223
|
+
enum: [
|
|
224
|
+
"@google_search",
|
|
225
|
+
"@youtube_search",
|
|
226
|
+
"@amazon_search",
|
|
227
|
+
"@reddit_search",
|
|
228
|
+
"@wikipedia_search",
|
|
229
|
+
"@twitter_search",
|
|
230
|
+
"@yelp_search",
|
|
231
|
+
"@spotify_search",
|
|
232
|
+
"@netflix_search",
|
|
233
|
+
"@linkedin_search",
|
|
234
|
+
"@instagram_search",
|
|
235
|
+
"@tiktok_search",
|
|
236
|
+
"@twitch_search",
|
|
237
|
+
],
|
|
238
|
+
},
|
|
239
|
+
query: { type: "string", description: "Search query (when using macro)" },
|
|
240
|
+
},
|
|
241
|
+
required: ["tabId"],
|
|
242
|
+
},
|
|
243
|
+
async execute(_id, params) {
|
|
244
|
+
const { tabId, ...rest } = params;
|
|
245
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
246
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/navigate`, {
|
|
247
|
+
method: "POST",
|
|
248
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
249
|
+
});
|
|
250
|
+
return toToolResult(result);
|
|
251
|
+
},
|
|
252
|
+
}));
|
|
253
|
+
api.registerTool((ctx) => ({
|
|
254
|
+
name: "camofox_scroll",
|
|
255
|
+
description: "Scroll a Camoufox page.",
|
|
256
|
+
parameters: {
|
|
257
|
+
type: "object",
|
|
258
|
+
properties: {
|
|
259
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
260
|
+
direction: { type: "string", enum: ["up", "down", "left", "right"] },
|
|
261
|
+
amount: { type: "number", description: "Pixels to scroll" },
|
|
262
|
+
},
|
|
263
|
+
required: ["tabId", "direction"],
|
|
264
|
+
},
|
|
265
|
+
async execute(_id, params) {
|
|
266
|
+
const { tabId, ...rest } = params;
|
|
267
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
268
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/scroll`, {
|
|
269
|
+
method: "POST",
|
|
270
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
271
|
+
});
|
|
272
|
+
return toToolResult(result);
|
|
273
|
+
},
|
|
274
|
+
}));
|
|
275
|
+
api.registerTool((ctx) => ({
|
|
276
|
+
name: "camofox_screenshot",
|
|
277
|
+
description: "Take a screenshot of a Camoufox page.",
|
|
278
|
+
parameters: {
|
|
279
|
+
type: "object",
|
|
280
|
+
properties: {
|
|
281
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
282
|
+
},
|
|
283
|
+
required: ["tabId"],
|
|
284
|
+
},
|
|
285
|
+
async execute(_id, params) {
|
|
286
|
+
const { tabId } = params;
|
|
287
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
288
|
+
const url = `${baseUrl}/tabs/${tabId}/screenshot?userId=${userId}`;
|
|
289
|
+
const res = await fetch(url);
|
|
290
|
+
if (!res.ok) {
|
|
291
|
+
const text = await res.text();
|
|
292
|
+
throw new Error(`${res.status}: ${text}`);
|
|
293
|
+
}
|
|
294
|
+
// Guard: if server returns JSON/text instead of image (e.g. error with 200),
|
|
295
|
+
// return as text to avoid crashing the client with base64-encoded JSON.
|
|
296
|
+
const contentType = res.headers.get('content-type') || '';
|
|
297
|
+
if (!contentType.startsWith('image/')) {
|
|
298
|
+
const text = await res.text();
|
|
299
|
+
return { content: [{ type: "text", text: `Screenshot failed: ${text}` }] };
|
|
300
|
+
}
|
|
301
|
+
const arrayBuffer = await res.arrayBuffer();
|
|
302
|
+
const base64 = Buffer.from(arrayBuffer).toString("base64");
|
|
303
|
+
return {
|
|
304
|
+
content: [
|
|
305
|
+
{
|
|
306
|
+
type: "image",
|
|
307
|
+
data: base64,
|
|
308
|
+
mimeType: contentType || "image/png",
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
};
|
|
312
|
+
},
|
|
313
|
+
}));
|
|
314
|
+
api.registerTool((ctx) => ({
|
|
315
|
+
name: "camofox_close_tab",
|
|
316
|
+
description: "Close a Camoufox browser tab.",
|
|
317
|
+
parameters: {
|
|
318
|
+
type: "object",
|
|
319
|
+
properties: {
|
|
320
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
321
|
+
},
|
|
322
|
+
required: ["tabId"],
|
|
323
|
+
},
|
|
324
|
+
async execute(_id, params) {
|
|
325
|
+
const { tabId } = params;
|
|
326
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
327
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}?userId=${userId}`, {
|
|
328
|
+
method: "DELETE",
|
|
329
|
+
});
|
|
330
|
+
return toToolResult(result);
|
|
331
|
+
},
|
|
332
|
+
}));
|
|
333
|
+
api.registerTool((ctx) => ({
|
|
334
|
+
name: "camofox_evaluate",
|
|
335
|
+
description: "Execute JavaScript in a Camoufox tab's page context. Returns the result of the expression. Use for injecting scripts, reading page state, or calling web app APIs.",
|
|
336
|
+
parameters: {
|
|
337
|
+
type: "object",
|
|
338
|
+
properties: {
|
|
339
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
340
|
+
expression: { type: "string", description: "JavaScript expression to evaluate in the page context" },
|
|
341
|
+
},
|
|
342
|
+
required: ["tabId", "expression"],
|
|
343
|
+
},
|
|
344
|
+
async execute(_id, params) {
|
|
345
|
+
const { tabId, expression } = params;
|
|
346
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
347
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/evaluate`, {
|
|
348
|
+
method: "POST",
|
|
349
|
+
body: JSON.stringify({ userId, expression }),
|
|
350
|
+
});
|
|
351
|
+
return toToolResult(result);
|
|
352
|
+
},
|
|
353
|
+
}));
|
|
354
|
+
api.registerTool((ctx) => ({
|
|
355
|
+
name: "camofox_list_tabs",
|
|
356
|
+
description: "List all open Camoufox tabs for a user.",
|
|
357
|
+
parameters: {
|
|
358
|
+
type: "object",
|
|
359
|
+
properties: {},
|
|
360
|
+
required: [],
|
|
361
|
+
},
|
|
362
|
+
async execute(_id, _params) {
|
|
363
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
364
|
+
const result = await fetchApi(baseUrl, `/tabs?userId=${userId}`);
|
|
365
|
+
return toToolResult(result);
|
|
366
|
+
},
|
|
367
|
+
}));
|
|
368
|
+
api.registerTool((ctx) => ({
|
|
369
|
+
name: "camofox_import_cookies",
|
|
370
|
+
description: "Import cookies into the current Camoufox user session (Netscape cookie file). Use to authenticate to sites like LinkedIn without interactive login.",
|
|
371
|
+
parameters: {
|
|
372
|
+
type: "object",
|
|
373
|
+
properties: {
|
|
374
|
+
cookiesPath: { type: "string", description: "Path to Netscape-format cookies.txt file" },
|
|
375
|
+
domainSuffix: {
|
|
376
|
+
type: "string",
|
|
377
|
+
description: "Only import cookies whose domain ends with this suffix",
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
required: ["cookiesPath"],
|
|
381
|
+
},
|
|
382
|
+
async execute(_id, params) {
|
|
383
|
+
const { cookiesPath, domainSuffix } = params;
|
|
384
|
+
const userId = ctx.agentId || fallbackUserId;
|
|
385
|
+
const envCfg = loadConfig();
|
|
386
|
+
const cookiesDir = resolve(envCfg.cookiesDir);
|
|
387
|
+
const pwCookies = await readCookieFile({
|
|
388
|
+
cookiesDir,
|
|
389
|
+
cookiesPath,
|
|
390
|
+
domainSuffix,
|
|
391
|
+
});
|
|
392
|
+
if (!envCfg.apiKey) {
|
|
393
|
+
throw new Error("CAMOFOX_API_KEY is not set. Cookie import is disabled unless you set CAMOFOX_API_KEY for both the server and the OpenClaw plugin environment.");
|
|
394
|
+
}
|
|
395
|
+
const result = await fetchApi(baseUrl, `/sessions/${encodeURIComponent(userId)}/cookies`, {
|
|
396
|
+
method: "POST",
|
|
397
|
+
headers: {
|
|
398
|
+
Authorization: `Bearer ${envCfg.apiKey}`,
|
|
399
|
+
},
|
|
400
|
+
body: JSON.stringify({ cookies: pwCookies }),
|
|
401
|
+
});
|
|
402
|
+
return toToolResult({ imported: pwCookies.length, userId, result });
|
|
403
|
+
},
|
|
404
|
+
}));
|
|
405
|
+
api.registerCommand({
|
|
406
|
+
name: "camofox",
|
|
407
|
+
description: "Camoufox browser server control (status, start, stop)",
|
|
408
|
+
handler: async (args) => {
|
|
409
|
+
const subcommand = args[0] || "status";
|
|
410
|
+
switch (subcommand) {
|
|
411
|
+
case "status":
|
|
412
|
+
try {
|
|
413
|
+
const health = await fetchApi(baseUrl, "/health");
|
|
414
|
+
api.log?.info?.(`Camoufox server at ${baseUrl}: ${JSON.stringify(health)}`);
|
|
415
|
+
}
|
|
416
|
+
catch {
|
|
417
|
+
api.log?.error?.(`Camoufox server at ${baseUrl}: not reachable`);
|
|
418
|
+
}
|
|
419
|
+
break;
|
|
420
|
+
case "start":
|
|
421
|
+
if (serverProcess) {
|
|
422
|
+
api.log?.info?.("Camoufox server already running (managed)");
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
if (await checkServerRunning(baseUrl)) {
|
|
426
|
+
api.log?.info?.(`Camoufox server already running at ${baseUrl}`);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
try {
|
|
430
|
+
serverProcess = await startServer(pluginDir, port, api.log, cfg);
|
|
431
|
+
}
|
|
432
|
+
catch (err) {
|
|
433
|
+
api.log?.error?.(`Failed to start server: ${err.message}`);
|
|
434
|
+
}
|
|
435
|
+
break;
|
|
436
|
+
case "stop":
|
|
437
|
+
if (serverProcess) {
|
|
438
|
+
serverProcess.kill();
|
|
439
|
+
serverProcess = null;
|
|
440
|
+
api.log?.info?.("Stopped camofox-browser server");
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
api.log?.info?.("No managed server process running");
|
|
444
|
+
}
|
|
445
|
+
break;
|
|
446
|
+
default:
|
|
447
|
+
api.log?.error?.(`Unknown subcommand: ${subcommand}. Use: status, start, stop`);
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
});
|
|
451
|
+
// Register health check for openclaw doctor/status
|
|
452
|
+
if (api.registerHealthCheck) {
|
|
453
|
+
api.registerHealthCheck("camofox-browser", async () => {
|
|
454
|
+
try {
|
|
455
|
+
const health = (await fetchApi(baseUrl, "/health"));
|
|
456
|
+
return {
|
|
457
|
+
status: "ok",
|
|
458
|
+
message: `Server running (${health.engine || "camoufox"})`,
|
|
459
|
+
details: {
|
|
460
|
+
url: baseUrl,
|
|
461
|
+
engine: health.engine,
|
|
462
|
+
activeTabs: health.activeTabs,
|
|
463
|
+
managed: serverProcess !== null,
|
|
464
|
+
},
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
catch {
|
|
468
|
+
return {
|
|
469
|
+
status: serverProcess ? "warn" : "error",
|
|
470
|
+
message: serverProcess
|
|
471
|
+
? "Server starting..."
|
|
472
|
+
: `Server not reachable at ${baseUrl}`,
|
|
473
|
+
details: {
|
|
474
|
+
url: baseUrl,
|
|
475
|
+
managed: serverProcess !== null,
|
|
476
|
+
hint: "Run: openclaw camofox start",
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
// Register RPC methods for gateway integration
|
|
483
|
+
if (api.registerRpc) {
|
|
484
|
+
api.registerRpc("camofox.health", async () => {
|
|
485
|
+
try {
|
|
486
|
+
const health = await fetchApi(baseUrl, "/health");
|
|
487
|
+
return { status: "ok", ...health };
|
|
488
|
+
}
|
|
489
|
+
catch (err) {
|
|
490
|
+
return { status: "error", error: err.message };
|
|
491
|
+
}
|
|
492
|
+
});
|
|
493
|
+
api.registerRpc("camofox.status", async () => {
|
|
494
|
+
const running = await checkServerRunning(baseUrl);
|
|
495
|
+
return {
|
|
496
|
+
running,
|
|
497
|
+
managed: serverProcess !== null,
|
|
498
|
+
pid: serverProcess?.pid || null,
|
|
499
|
+
url: baseUrl,
|
|
500
|
+
port,
|
|
501
|
+
};
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
// Register CLI subcommands (openclaw camofox ...)
|
|
505
|
+
if (api.registerCli) {
|
|
506
|
+
api.registerCli(({ program }) => {
|
|
507
|
+
const camofox = program
|
|
508
|
+
.command("camofox")
|
|
509
|
+
.description("Camoufox anti-detection browser automation");
|
|
510
|
+
camofox
|
|
511
|
+
.command("status")
|
|
512
|
+
.description("Show server status")
|
|
513
|
+
.action(async () => {
|
|
514
|
+
try {
|
|
515
|
+
const health = (await fetchApi(baseUrl, "/health"));
|
|
516
|
+
console.log(`Camoufox server: ${health.status}`);
|
|
517
|
+
console.log(` URL: ${baseUrl}`);
|
|
518
|
+
console.log(` Engine: ${health.engine || "camoufox"}`);
|
|
519
|
+
console.log(` Active tabs: ${health.activeTabs ?? 0}`);
|
|
520
|
+
console.log(` Managed: ${serverProcess !== null}`);
|
|
521
|
+
}
|
|
522
|
+
catch {
|
|
523
|
+
console.log(`Camoufox server: not reachable`);
|
|
524
|
+
console.log(` URL: ${baseUrl}`);
|
|
525
|
+
console.log(` Managed: ${serverProcess !== null}`);
|
|
526
|
+
console.log(` Hint: Run 'openclaw camofox start' to start the server`);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
529
|
+
camofox
|
|
530
|
+
.command("start")
|
|
531
|
+
.description("Start the camofox server")
|
|
532
|
+
.action(async () => {
|
|
533
|
+
if (serverProcess) {
|
|
534
|
+
console.log("Camoufox server already running (managed by plugin)");
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if (await checkServerRunning(baseUrl)) {
|
|
538
|
+
console.log(`Camoufox server already running at ${baseUrl}`);
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
try {
|
|
542
|
+
console.log(`Starting camofox server on port ${port}...`);
|
|
543
|
+
serverProcess = await startServer(pluginDir, port, api.log, cfg);
|
|
544
|
+
console.log(`Camoufox server started at ${baseUrl}`);
|
|
545
|
+
}
|
|
546
|
+
catch (err) {
|
|
547
|
+
console.error(`Failed to start server: ${err.message}`);
|
|
548
|
+
process.exit(1);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
camofox
|
|
552
|
+
.command("stop")
|
|
553
|
+
.description("Stop the camofox server")
|
|
554
|
+
.action(async () => {
|
|
555
|
+
if (serverProcess) {
|
|
556
|
+
serverProcess.kill();
|
|
557
|
+
serverProcess = null;
|
|
558
|
+
console.log("Stopped camofox server");
|
|
559
|
+
}
|
|
560
|
+
else {
|
|
561
|
+
console.log("No managed server process running");
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
camofox
|
|
565
|
+
.command("configure")
|
|
566
|
+
.description("Configure camofox plugin settings")
|
|
567
|
+
.action(async () => {
|
|
568
|
+
console.log("Camoufox Browser Configuration");
|
|
569
|
+
console.log("================================");
|
|
570
|
+
console.log("");
|
|
571
|
+
console.log("Current settings:");
|
|
572
|
+
console.log(` Server URL: ${baseUrl}`);
|
|
573
|
+
console.log(` Port: ${port}`);
|
|
574
|
+
console.log(` Auto-start: ${autoStart}`);
|
|
575
|
+
console.log("");
|
|
576
|
+
console.log("Plugin config (openclaw.json):");
|
|
577
|
+
console.log("");
|
|
578
|
+
console.log(" plugins:");
|
|
579
|
+
console.log(" entries:");
|
|
580
|
+
console.log(" camofox-browser:");
|
|
581
|
+
console.log(" enabled: true");
|
|
582
|
+
console.log(" config:");
|
|
583
|
+
console.log(" port: 9377");
|
|
584
|
+
console.log(" autoStart: true");
|
|
585
|
+
console.log("");
|
|
586
|
+
console.log("To use camofox as the ONLY browser tool, disable the built-in:");
|
|
587
|
+
console.log("");
|
|
588
|
+
console.log(" tools:");
|
|
589
|
+
console.log(' deny: ["browser"]');
|
|
590
|
+
console.log("");
|
|
591
|
+
console.log("This removes OpenClaw's built-in browser tool, leaving camofox tools.");
|
|
592
|
+
});
|
|
593
|
+
camofox
|
|
594
|
+
.command("tabs")
|
|
595
|
+
.description("List active browser tabs")
|
|
596
|
+
.option("--user <userId>", "Filter by user ID")
|
|
597
|
+
.action(async (opts) => {
|
|
598
|
+
try {
|
|
599
|
+
const endpoint = opts.user ? `/tabs?userId=${opts.user}` : "/tabs";
|
|
600
|
+
const tabs = (await fetchApi(baseUrl, endpoint));
|
|
601
|
+
if (tabs.length === 0) {
|
|
602
|
+
console.log("No active tabs");
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
console.log(`Active tabs (${tabs.length}):`);
|
|
606
|
+
for (const tab of tabs) {
|
|
607
|
+
console.log(` ${tab.tabId} [${tab.userId}] ${tab.title || tab.url}`);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch (err) {
|
|
611
|
+
console.error(`Failed to list tabs: ${err.message}`);
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
}, { commands: ["camofox"] });
|
|
615
|
+
}
|
|
616
|
+
}
|