@askjo/camofox-browser 1.0.12
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/Dockerfile.camoufox +59 -0
- package/LICENSE +21 -0
- package/README.md +145 -0
- package/lib/macros.js +30 -0
- package/openclaw.plugin.json +39 -0
- package/package.json +68 -0
- package/plugin.ts +647 -0
- package/run-camoufox.sh +37 -0
- package/server-camoufox.js +1288 -0
package/plugin.ts
ADDED
|
@@ -0,0 +1,647 @@
|
|
|
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
|
+
|
|
8
|
+
import { spawn, ChildProcess } from "child_process";
|
|
9
|
+
import { join, dirname } from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
11
|
+
|
|
12
|
+
// Get plugin directory - works in both ESM and CJS contexts
|
|
13
|
+
const getPluginDir = (): string => {
|
|
14
|
+
try {
|
|
15
|
+
// ESM context
|
|
16
|
+
return dirname(fileURLToPath(import.meta.url));
|
|
17
|
+
} catch {
|
|
18
|
+
// CJS context
|
|
19
|
+
return __dirname;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
interface PluginConfig {
|
|
24
|
+
url?: string;
|
|
25
|
+
autoStart?: boolean;
|
|
26
|
+
port?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface ToolResult {
|
|
30
|
+
content: Array<{ type: string; text: string }>;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface HealthCheckResult {
|
|
34
|
+
status: "ok" | "warn" | "error";
|
|
35
|
+
message?: string;
|
|
36
|
+
details?: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface CliContext {
|
|
40
|
+
program: {
|
|
41
|
+
command: (name: string) => {
|
|
42
|
+
description: (desc: string) => CliContext["program"];
|
|
43
|
+
option: (flags: string, desc: string, defaultValue?: string) => CliContext["program"];
|
|
44
|
+
argument: (name: string, desc: string) => CliContext["program"];
|
|
45
|
+
action: (handler: (...args: unknown[]) => void | Promise<void>) => CliContext["program"];
|
|
46
|
+
command: (name: string) => CliContext["program"];
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
config: PluginConfig;
|
|
50
|
+
logger: {
|
|
51
|
+
info: (msg: string) => void;
|
|
52
|
+
error: (msg: string) => void;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
interface ToolContext {
|
|
57
|
+
sessionKey?: string;
|
|
58
|
+
agentId?: string;
|
|
59
|
+
workspaceDir?: string;
|
|
60
|
+
sandboxed?: boolean;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
type ToolDefinition = {
|
|
64
|
+
name: string;
|
|
65
|
+
description: string;
|
|
66
|
+
parameters: object;
|
|
67
|
+
execute: (id: string, params: Record<string, unknown>) => Promise<ToolResult>;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
type ToolFactory = (ctx: ToolContext) => ToolDefinition | ToolDefinition[] | null | undefined;
|
|
71
|
+
|
|
72
|
+
interface PluginApi {
|
|
73
|
+
registerTool: (
|
|
74
|
+
tool: ToolDefinition | ToolFactory,
|
|
75
|
+
options?: { optional?: boolean }
|
|
76
|
+
) => void;
|
|
77
|
+
registerCommand: (cmd: {
|
|
78
|
+
name: string;
|
|
79
|
+
description: string;
|
|
80
|
+
handler: (args: string[]) => Promise<void>;
|
|
81
|
+
}) => void;
|
|
82
|
+
registerCli?: (
|
|
83
|
+
registrar: (ctx: CliContext) => void | Promise<void>,
|
|
84
|
+
opts?: { commands?: string[] }
|
|
85
|
+
) => void;
|
|
86
|
+
registerRpc?: (
|
|
87
|
+
name: string,
|
|
88
|
+
handler: (params: Record<string, unknown>) => Promise<unknown>
|
|
89
|
+
) => void;
|
|
90
|
+
registerHealthCheck?: (
|
|
91
|
+
name: string,
|
|
92
|
+
check: () => Promise<HealthCheckResult>
|
|
93
|
+
) => void;
|
|
94
|
+
config: PluginConfig;
|
|
95
|
+
log: {
|
|
96
|
+
info: (msg: string) => void;
|
|
97
|
+
error: (msg: string) => void;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
let serverProcess: ChildProcess | null = null;
|
|
102
|
+
|
|
103
|
+
async function startServer(
|
|
104
|
+
pluginDir: string,
|
|
105
|
+
port: number,
|
|
106
|
+
log: PluginApi["log"]
|
|
107
|
+
): Promise<ChildProcess> {
|
|
108
|
+
const serverPath = join(pluginDir, "server-camoufox.js");
|
|
109
|
+
const proc = spawn("node", [serverPath], {
|
|
110
|
+
cwd: pluginDir,
|
|
111
|
+
env: { ...process.env, PORT: String(port) },
|
|
112
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
113
|
+
detached: false,
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
proc.stdout?.on("data", (data: Buffer) => {
|
|
117
|
+
const msg = data.toString().trim();
|
|
118
|
+
if (msg) log?.info?.(`[server] ${msg}`);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
proc.stderr?.on("data", (data: Buffer) => {
|
|
122
|
+
const msg = data.toString().trim();
|
|
123
|
+
if (msg) log?.error?.(`[server] ${msg}`);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
proc.on("error", (err) => {
|
|
127
|
+
log?.error?.(`Server process error: ${err.message}`);
|
|
128
|
+
serverProcess = null;
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
proc.on("exit", (code) => {
|
|
132
|
+
if (code !== 0 && code !== null) {
|
|
133
|
+
log?.error?.(`Server exited with code ${code}`);
|
|
134
|
+
}
|
|
135
|
+
serverProcess = null;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Wait for server to be ready
|
|
139
|
+
const baseUrl = `http://localhost:${port}`;
|
|
140
|
+
for (let i = 0; i < 30; i++) {
|
|
141
|
+
await new Promise((r) => setTimeout(r, 500));
|
|
142
|
+
try {
|
|
143
|
+
const res = await fetch(`${baseUrl}/health`);
|
|
144
|
+
if (res.ok) {
|
|
145
|
+
log.info(`Camoufox server ready on port ${port}`);
|
|
146
|
+
return proc;
|
|
147
|
+
}
|
|
148
|
+
} catch {
|
|
149
|
+
// Server not ready yet
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
throw new Error("Server failed to start within 15 seconds");
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function checkServerRunning(baseUrl: string): Promise<boolean> {
|
|
156
|
+
try {
|
|
157
|
+
const res = await fetch(`${baseUrl}/health`);
|
|
158
|
+
return res.ok;
|
|
159
|
+
} catch {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async function fetchApi(
|
|
165
|
+
baseUrl: string,
|
|
166
|
+
path: string,
|
|
167
|
+
options: RequestInit = {}
|
|
168
|
+
): Promise<unknown> {
|
|
169
|
+
const url = `${baseUrl}${path}`;
|
|
170
|
+
const res = await fetch(url, {
|
|
171
|
+
...options,
|
|
172
|
+
headers: {
|
|
173
|
+
"Content-Type": "application/json",
|
|
174
|
+
...options.headers,
|
|
175
|
+
},
|
|
176
|
+
});
|
|
177
|
+
if (!res.ok) {
|
|
178
|
+
const text = await res.text();
|
|
179
|
+
throw new Error(`${res.status}: ${text}`);
|
|
180
|
+
}
|
|
181
|
+
return res.json();
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function toToolResult(data: unknown): ToolResult {
|
|
185
|
+
return {
|
|
186
|
+
content: [{ type: "text", text: JSON.stringify(data, null, 2) }],
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export default function register(api: PluginApi) {
|
|
191
|
+
const port = api.config.port || 9377;
|
|
192
|
+
const baseUrl = api.config.url || `http://localhost:${port}`;
|
|
193
|
+
const autoStart = api.config.autoStart !== false; // default true
|
|
194
|
+
const pluginDir = getPluginDir();
|
|
195
|
+
|
|
196
|
+
// Auto-start server if configured (default: true)
|
|
197
|
+
if (autoStart) {
|
|
198
|
+
(async () => {
|
|
199
|
+
const alreadyRunning = await checkServerRunning(baseUrl);
|
|
200
|
+
if (alreadyRunning) {
|
|
201
|
+
api.log?.info?.(`Camoufox server already running at ${baseUrl}`);
|
|
202
|
+
} else {
|
|
203
|
+
try {
|
|
204
|
+
serverProcess = await startServer(pluginDir, port, api.log);
|
|
205
|
+
} catch (err) {
|
|
206
|
+
api.log?.error?.(`Failed to auto-start server: ${(err as Error).message}`);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
})();
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
213
|
+
name: "camofox_create_tab",
|
|
214
|
+
description:
|
|
215
|
+
"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.",
|
|
216
|
+
parameters: {
|
|
217
|
+
type: "object",
|
|
218
|
+
properties: {
|
|
219
|
+
url: { type: "string", description: "Initial URL to navigate to" },
|
|
220
|
+
},
|
|
221
|
+
required: ["url"],
|
|
222
|
+
},
|
|
223
|
+
async execute(_id, params) {
|
|
224
|
+
const sessionKey = ctx.sessionKey || "default";
|
|
225
|
+
const userId = ctx.agentId || "openclaw";
|
|
226
|
+
const result = await fetchApi(baseUrl, "/tabs", {
|
|
227
|
+
method: "POST",
|
|
228
|
+
body: JSON.stringify({ ...params, userId, sessionKey }),
|
|
229
|
+
});
|
|
230
|
+
return toToolResult(result);
|
|
231
|
+
},
|
|
232
|
+
}));
|
|
233
|
+
|
|
234
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
235
|
+
name: "camofox_snapshot",
|
|
236
|
+
description:
|
|
237
|
+
"Get accessibility snapshot of a Camoufox page with element refs (e1, e2, etc.) for interaction. Use with camofox_create_tab.",
|
|
238
|
+
parameters: {
|
|
239
|
+
type: "object",
|
|
240
|
+
properties: {
|
|
241
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
242
|
+
},
|
|
243
|
+
required: ["tabId"],
|
|
244
|
+
},
|
|
245
|
+
async execute(_id, params) {
|
|
246
|
+
const { tabId } = params as { tabId: string };
|
|
247
|
+
const userId = ctx.agentId || "openclaw";
|
|
248
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/snapshot?userId=${userId}`);
|
|
249
|
+
return toToolResult(result);
|
|
250
|
+
},
|
|
251
|
+
}));
|
|
252
|
+
|
|
253
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
254
|
+
name: "camofox_click",
|
|
255
|
+
description: "Click an element in a Camoufox tab by ref (e.g., e1) or CSS selector.",
|
|
256
|
+
parameters: {
|
|
257
|
+
type: "object",
|
|
258
|
+
properties: {
|
|
259
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
260
|
+
ref: { type: "string", description: "Element ref from snapshot (e.g., e1)" },
|
|
261
|
+
selector: { type: "string", description: "CSS selector (alternative to ref)" },
|
|
262
|
+
},
|
|
263
|
+
required: ["tabId"],
|
|
264
|
+
},
|
|
265
|
+
async execute(_id, params) {
|
|
266
|
+
const { tabId, ...rest } = params as { tabId: string } & Record<string, unknown>;
|
|
267
|
+
const userId = ctx.agentId || "openclaw";
|
|
268
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/click`, {
|
|
269
|
+
method: "POST",
|
|
270
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
271
|
+
});
|
|
272
|
+
return toToolResult(result);
|
|
273
|
+
},
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
277
|
+
name: "camofox_type",
|
|
278
|
+
description: "Type text into an element in a Camoufox tab.",
|
|
279
|
+
parameters: {
|
|
280
|
+
type: "object",
|
|
281
|
+
properties: {
|
|
282
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
283
|
+
ref: { type: "string", description: "Element ref from snapshot (e.g., e2)" },
|
|
284
|
+
selector: { type: "string", description: "CSS selector (alternative to ref)" },
|
|
285
|
+
text: { type: "string", description: "Text to type" },
|
|
286
|
+
pressEnter: { type: "boolean", description: "Press Enter after typing" },
|
|
287
|
+
},
|
|
288
|
+
required: ["tabId", "text"],
|
|
289
|
+
},
|
|
290
|
+
async execute(_id, params) {
|
|
291
|
+
const { tabId, ...rest } = params as { tabId: string } & Record<string, unknown>;
|
|
292
|
+
const userId = ctx.agentId || "openclaw";
|
|
293
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/type`, {
|
|
294
|
+
method: "POST",
|
|
295
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
296
|
+
});
|
|
297
|
+
return toToolResult(result);
|
|
298
|
+
},
|
|
299
|
+
}));
|
|
300
|
+
|
|
301
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
302
|
+
name: "camofox_navigate",
|
|
303
|
+
description:
|
|
304
|
+
"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.",
|
|
305
|
+
parameters: {
|
|
306
|
+
type: "object",
|
|
307
|
+
properties: {
|
|
308
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
309
|
+
url: { type: "string", description: "URL to navigate to" },
|
|
310
|
+
macro: {
|
|
311
|
+
type: "string",
|
|
312
|
+
description: "Search macro (e.g., @google_search, @youtube_search)",
|
|
313
|
+
enum: [
|
|
314
|
+
"@google_search",
|
|
315
|
+
"@youtube_search",
|
|
316
|
+
"@amazon_search",
|
|
317
|
+
"@reddit_search",
|
|
318
|
+
"@wikipedia_search",
|
|
319
|
+
"@twitter_search",
|
|
320
|
+
"@yelp_search",
|
|
321
|
+
"@spotify_search",
|
|
322
|
+
"@netflix_search",
|
|
323
|
+
"@linkedin_search",
|
|
324
|
+
"@instagram_search",
|
|
325
|
+
"@tiktok_search",
|
|
326
|
+
"@twitch_search",
|
|
327
|
+
],
|
|
328
|
+
},
|
|
329
|
+
query: { type: "string", description: "Search query (when using macro)" },
|
|
330
|
+
},
|
|
331
|
+
required: ["tabId"],
|
|
332
|
+
},
|
|
333
|
+
async execute(_id, params) {
|
|
334
|
+
const { tabId, ...rest } = params as { tabId: string } & Record<string, unknown>;
|
|
335
|
+
const userId = ctx.agentId || "openclaw";
|
|
336
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/navigate`, {
|
|
337
|
+
method: "POST",
|
|
338
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
339
|
+
});
|
|
340
|
+
return toToolResult(result);
|
|
341
|
+
},
|
|
342
|
+
}));
|
|
343
|
+
|
|
344
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
345
|
+
name: "camofox_scroll",
|
|
346
|
+
description: "Scroll a Camoufox page.",
|
|
347
|
+
parameters: {
|
|
348
|
+
type: "object",
|
|
349
|
+
properties: {
|
|
350
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
351
|
+
direction: { type: "string", enum: ["up", "down", "left", "right"] },
|
|
352
|
+
amount: { type: "number", description: "Pixels to scroll" },
|
|
353
|
+
},
|
|
354
|
+
required: ["tabId", "direction"],
|
|
355
|
+
},
|
|
356
|
+
async execute(_id, params) {
|
|
357
|
+
const { tabId, ...rest } = params as { tabId: string } & Record<string, unknown>;
|
|
358
|
+
const userId = ctx.agentId || "openclaw";
|
|
359
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/scroll`, {
|
|
360
|
+
method: "POST",
|
|
361
|
+
body: JSON.stringify({ ...rest, userId }),
|
|
362
|
+
});
|
|
363
|
+
return toToolResult(result);
|
|
364
|
+
},
|
|
365
|
+
}));
|
|
366
|
+
|
|
367
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
368
|
+
name: "camofox_screenshot",
|
|
369
|
+
description: "Take a screenshot of a Camoufox page.",
|
|
370
|
+
parameters: {
|
|
371
|
+
type: "object",
|
|
372
|
+
properties: {
|
|
373
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
374
|
+
},
|
|
375
|
+
required: ["tabId"],
|
|
376
|
+
},
|
|
377
|
+
async execute(_id, params) {
|
|
378
|
+
const { tabId } = params as { tabId: string };
|
|
379
|
+
const userId = ctx.agentId || "openclaw";
|
|
380
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}/screenshot?userId=${userId}`);
|
|
381
|
+
return toToolResult(result);
|
|
382
|
+
},
|
|
383
|
+
}));
|
|
384
|
+
|
|
385
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
386
|
+
name: "camofox_close_tab",
|
|
387
|
+
description: "Close a Camoufox browser tab.",
|
|
388
|
+
parameters: {
|
|
389
|
+
type: "object",
|
|
390
|
+
properties: {
|
|
391
|
+
tabId: { type: "string", description: "Tab identifier" },
|
|
392
|
+
},
|
|
393
|
+
required: ["tabId"],
|
|
394
|
+
},
|
|
395
|
+
async execute(_id, params) {
|
|
396
|
+
const { tabId } = params as { tabId: string };
|
|
397
|
+
const userId = ctx.agentId || "openclaw";
|
|
398
|
+
const result = await fetchApi(baseUrl, `/tabs/${tabId}?userId=${userId}`, {
|
|
399
|
+
method: "DELETE",
|
|
400
|
+
});
|
|
401
|
+
return toToolResult(result);
|
|
402
|
+
},
|
|
403
|
+
}));
|
|
404
|
+
|
|
405
|
+
api.registerTool((ctx: ToolContext) => ({
|
|
406
|
+
name: "camofox_list_tabs",
|
|
407
|
+
description: "List all open Camoufox tabs for a user.",
|
|
408
|
+
parameters: {
|
|
409
|
+
type: "object",
|
|
410
|
+
properties: {},
|
|
411
|
+
required: [],
|
|
412
|
+
},
|
|
413
|
+
async execute(_id, _params) {
|
|
414
|
+
const userId = ctx.agentId || "openclaw";
|
|
415
|
+
const result = await fetchApi(baseUrl, `/tabs?userId=${userId}`);
|
|
416
|
+
return toToolResult(result);
|
|
417
|
+
},
|
|
418
|
+
}));
|
|
419
|
+
|
|
420
|
+
api.registerCommand({
|
|
421
|
+
name: "camofox",
|
|
422
|
+
description: "Camoufox browser server control (status, start, stop)",
|
|
423
|
+
handler: async (args) => {
|
|
424
|
+
const subcommand = args[0] || "status";
|
|
425
|
+
switch (subcommand) {
|
|
426
|
+
case "status":
|
|
427
|
+
try {
|
|
428
|
+
const health = await fetchApi(baseUrl, "/health");
|
|
429
|
+
api.log?.info?.(`Camoufox server at ${baseUrl}: ${JSON.stringify(health)}`);
|
|
430
|
+
} catch {
|
|
431
|
+
api.log?.error?.(`Camoufox server at ${baseUrl}: not reachable`);
|
|
432
|
+
}
|
|
433
|
+
break;
|
|
434
|
+
case "start":
|
|
435
|
+
if (serverProcess) {
|
|
436
|
+
api.log?.info?.("Camoufox server already running (managed)");
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
if (await checkServerRunning(baseUrl)) {
|
|
440
|
+
api.log?.info?.(`Camoufox server already running at ${baseUrl}`);
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
try {
|
|
444
|
+
serverProcess = await startServer(pluginDir, port, api.log);
|
|
445
|
+
} catch (err) {
|
|
446
|
+
api.log?.error?.(`Failed to start server: ${(err as Error).message}`);
|
|
447
|
+
}
|
|
448
|
+
break;
|
|
449
|
+
case "stop":
|
|
450
|
+
if (serverProcess) {
|
|
451
|
+
serverProcess.kill();
|
|
452
|
+
serverProcess = null;
|
|
453
|
+
api.log?.info?.("Stopped camofox-browser server");
|
|
454
|
+
} else {
|
|
455
|
+
api.log?.info?.("No managed server process running");
|
|
456
|
+
}
|
|
457
|
+
break;
|
|
458
|
+
default:
|
|
459
|
+
api.log?.error?.(`Unknown subcommand: ${subcommand}. Use: status, start, stop`);
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
// Register health check for openclaw doctor/status
|
|
465
|
+
if (api.registerHealthCheck) {
|
|
466
|
+
api.registerHealthCheck("camofox-browser", async () => {
|
|
467
|
+
try {
|
|
468
|
+
const health = (await fetchApi(baseUrl, "/health")) as {
|
|
469
|
+
status: string;
|
|
470
|
+
engine?: string;
|
|
471
|
+
activeTabs?: number;
|
|
472
|
+
};
|
|
473
|
+
return {
|
|
474
|
+
status: "ok",
|
|
475
|
+
message: `Server running (${health.engine || "camoufox"})`,
|
|
476
|
+
details: {
|
|
477
|
+
url: baseUrl,
|
|
478
|
+
engine: health.engine,
|
|
479
|
+
activeTabs: health.activeTabs,
|
|
480
|
+
managed: serverProcess !== null,
|
|
481
|
+
},
|
|
482
|
+
};
|
|
483
|
+
} catch {
|
|
484
|
+
return {
|
|
485
|
+
status: serverProcess ? "warn" : "error",
|
|
486
|
+
message: serverProcess
|
|
487
|
+
? "Server starting..."
|
|
488
|
+
: `Server not reachable at ${baseUrl}`,
|
|
489
|
+
details: {
|
|
490
|
+
url: baseUrl,
|
|
491
|
+
managed: serverProcess !== null,
|
|
492
|
+
hint: "Run: openclaw camofox start",
|
|
493
|
+
},
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Register RPC methods for gateway integration
|
|
500
|
+
if (api.registerRpc) {
|
|
501
|
+
api.registerRpc("camofox.health", async () => {
|
|
502
|
+
try {
|
|
503
|
+
const health = await fetchApi(baseUrl, "/health");
|
|
504
|
+
return { status: "ok", ...health };
|
|
505
|
+
} catch (err) {
|
|
506
|
+
return { status: "error", error: (err as Error).message };
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
|
|
510
|
+
api.registerRpc("camofox.status", async () => {
|
|
511
|
+
const running = await checkServerRunning(baseUrl);
|
|
512
|
+
return {
|
|
513
|
+
running,
|
|
514
|
+
managed: serverProcess !== null,
|
|
515
|
+
pid: serverProcess?.pid || null,
|
|
516
|
+
url: baseUrl,
|
|
517
|
+
port,
|
|
518
|
+
};
|
|
519
|
+
});
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// Register CLI subcommands (openclaw camofox ...)
|
|
523
|
+
if (api.registerCli) {
|
|
524
|
+
api.registerCli(
|
|
525
|
+
({ program }) => {
|
|
526
|
+
const camofox = program
|
|
527
|
+
.command("camofox")
|
|
528
|
+
.description("Camoufox anti-detection browser automation");
|
|
529
|
+
|
|
530
|
+
camofox
|
|
531
|
+
.command("status")
|
|
532
|
+
.description("Show server status")
|
|
533
|
+
.action(async () => {
|
|
534
|
+
try {
|
|
535
|
+
const health = (await fetchApi(baseUrl, "/health")) as {
|
|
536
|
+
status: string;
|
|
537
|
+
engine?: string;
|
|
538
|
+
activeTabs?: number;
|
|
539
|
+
};
|
|
540
|
+
console.log(`Camoufox server: ${health.status}`);
|
|
541
|
+
console.log(` URL: ${baseUrl}`);
|
|
542
|
+
console.log(` Engine: ${health.engine || "camoufox"}`);
|
|
543
|
+
console.log(` Active tabs: ${health.activeTabs ?? 0}`);
|
|
544
|
+
console.log(` Managed: ${serverProcess !== null}`);
|
|
545
|
+
} catch {
|
|
546
|
+
console.log(`Camoufox server: not reachable`);
|
|
547
|
+
console.log(` URL: ${baseUrl}`);
|
|
548
|
+
console.log(` Managed: ${serverProcess !== null}`);
|
|
549
|
+
console.log(` Hint: Run 'openclaw camofox start' to start the server`);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
camofox
|
|
554
|
+
.command("start")
|
|
555
|
+
.description("Start the camofox server")
|
|
556
|
+
.action(async () => {
|
|
557
|
+
if (serverProcess) {
|
|
558
|
+
console.log("Camoufox server already running (managed by plugin)");
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
if (await checkServerRunning(baseUrl)) {
|
|
562
|
+
console.log(`Camoufox server already running at ${baseUrl}`);
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
console.log(`Starting camofox server on port ${port}...`);
|
|
567
|
+
serverProcess = await startServer(pluginDir, port, api.log);
|
|
568
|
+
console.log(`Camoufox server started at ${baseUrl}`);
|
|
569
|
+
} catch (err) {
|
|
570
|
+
console.error(`Failed to start server: ${(err as Error).message}`);
|
|
571
|
+
process.exit(1);
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
camofox
|
|
576
|
+
.command("stop")
|
|
577
|
+
.description("Stop the camofox server")
|
|
578
|
+
.action(async () => {
|
|
579
|
+
if (serverProcess) {
|
|
580
|
+
serverProcess.kill();
|
|
581
|
+
serverProcess = null;
|
|
582
|
+
console.log("Stopped camofox server");
|
|
583
|
+
} else {
|
|
584
|
+
console.log("No managed server process running");
|
|
585
|
+
}
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
camofox
|
|
589
|
+
.command("configure")
|
|
590
|
+
.description("Configure camofox plugin settings")
|
|
591
|
+
.action(async () => {
|
|
592
|
+
console.log("Camoufox Browser Configuration");
|
|
593
|
+
console.log("================================");
|
|
594
|
+
console.log("");
|
|
595
|
+
console.log("Current settings:");
|
|
596
|
+
console.log(` Server URL: ${baseUrl}`);
|
|
597
|
+
console.log(` Port: ${port}`);
|
|
598
|
+
console.log(` Auto-start: ${autoStart}`);
|
|
599
|
+
console.log("");
|
|
600
|
+
console.log("Plugin config (openclaw.json):");
|
|
601
|
+
console.log("");
|
|
602
|
+
console.log(" plugins:");
|
|
603
|
+
console.log(" entries:");
|
|
604
|
+
console.log(" camofox-browser:");
|
|
605
|
+
console.log(" enabled: true");
|
|
606
|
+
console.log(" config:");
|
|
607
|
+
console.log(" port: 9377");
|
|
608
|
+
console.log(" autoStart: true");
|
|
609
|
+
console.log("");
|
|
610
|
+
console.log("To use camofox as the ONLY browser tool, disable the built-in:");
|
|
611
|
+
console.log("");
|
|
612
|
+
console.log(" tools:");
|
|
613
|
+
console.log(' deny: ["browser"]');
|
|
614
|
+
console.log("");
|
|
615
|
+
console.log("This removes OpenClaw's built-in browser tool, leaving camofox tools.");
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
camofox
|
|
619
|
+
.command("tabs")
|
|
620
|
+
.description("List active browser tabs")
|
|
621
|
+
.option("--user <userId>", "Filter by user ID")
|
|
622
|
+
.action(async (opts: { user?: string }) => {
|
|
623
|
+
try {
|
|
624
|
+
const endpoint = opts.user ? `/tabs?userId=${opts.user}` : "/tabs";
|
|
625
|
+
const tabs = (await fetchApi(baseUrl, endpoint)) as Array<{
|
|
626
|
+
tabId: string;
|
|
627
|
+
userId: string;
|
|
628
|
+
url: string;
|
|
629
|
+
title: string;
|
|
630
|
+
}>;
|
|
631
|
+
if (tabs.length === 0) {
|
|
632
|
+
console.log("No active tabs");
|
|
633
|
+
return;
|
|
634
|
+
}
|
|
635
|
+
console.log(`Active tabs (${tabs.length}):`);
|
|
636
|
+
for (const tab of tabs) {
|
|
637
|
+
console.log(` ${tab.tabId} [${tab.userId}] ${tab.title || tab.url}`);
|
|
638
|
+
}
|
|
639
|
+
} catch (err) {
|
|
640
|
+
console.error(`Failed to list tabs: ${(err as Error).message}`);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
},
|
|
644
|
+
{ commands: ["camofox"] }
|
|
645
|
+
);
|
|
646
|
+
}
|
|
647
|
+
}
|
package/run-camoufox.sh
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# Local development script for camoufox-browser
|
|
3
|
+
# Usage: ./run-camoufox.sh [-p port]
|
|
4
|
+
# Example: ./run-camoufox.sh -p 3001
|
|
5
|
+
|
|
6
|
+
PORT=3000
|
|
7
|
+
while getopts "p:" opt; do
|
|
8
|
+
case $opt in
|
|
9
|
+
p) PORT="$OPTARG" ;;
|
|
10
|
+
*) echo "Usage: $0 [-p port]"; exit 1 ;;
|
|
11
|
+
esac
|
|
12
|
+
done
|
|
13
|
+
export PORT
|
|
14
|
+
|
|
15
|
+
# Install deps if needed
|
|
16
|
+
if [ ! -d "node_modules" ]; then
|
|
17
|
+
echo "Installing dependencies..."
|
|
18
|
+
npm install
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
# Check if camoufox browser is installed
|
|
22
|
+
if ! npx camoufox-js --version &> /dev/null 2>&1; then
|
|
23
|
+
echo "Fetching Camoufox browser..."
|
|
24
|
+
npx camoufox-js fetch
|
|
25
|
+
fi
|
|
26
|
+
|
|
27
|
+
# Install nodemon globally if not available
|
|
28
|
+
if ! command -v nodemon &> /dev/null; then
|
|
29
|
+
echo "Installing nodemon..."
|
|
30
|
+
npm install -g nodemon
|
|
31
|
+
fi
|
|
32
|
+
|
|
33
|
+
echo "Starting camoufox-browser on http://localhost:$PORT (with auto-reload)"
|
|
34
|
+
echo "Logs: /tmp/camoufox-browser.log"
|
|
35
|
+
nodemon --watch server-camoufox.js --exec "node server-camoufox.js" 2>&1 | while IFS= read -r line; do
|
|
36
|
+
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $line"
|
|
37
|
+
done | tee -a /tmp/camoufox-browser.log
|