agentic-browser 1.6.1 → 2.0.1
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/README.md +5 -5
- package/dist/cli/index.mjs +165 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,8 +111,8 @@ agentic-browser agent start --user-profile default
|
|
|
111
111
|
agentic-browser agent start --headless
|
|
112
112
|
agentic-browser agent start --user-agent "MyBot/1.0"
|
|
113
113
|
agentic-browser agent status
|
|
114
|
-
agentic-browser agent
|
|
115
|
-
agentic-browser agent
|
|
114
|
+
agentic-browser agent navigate https://example.com
|
|
115
|
+
agentic-browser agent click "#login"
|
|
116
116
|
agentic-browser agent content --mode text
|
|
117
117
|
agentic-browser agent content --mode html --selector main
|
|
118
118
|
agentic-browser agent elements
|
|
@@ -132,7 +132,7 @@ agentic-browser agent elements --roles button,link,input --visible-only --limit
|
|
|
132
132
|
agentic-browser agent elements --selector "#main-content"
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
-
Returns a JSON array of elements with CSS selectors and fallback selectors usable in `agent
|
|
135
|
+
Returns a JSON array of elements with CSS selectors and fallback selectors usable in the typed agent commands like `agent click`, `agent type`, and `agent select`:
|
|
136
136
|
|
|
137
137
|
```json
|
|
138
138
|
{
|
|
@@ -255,7 +255,7 @@ agentic-browser memory:stats
|
|
|
255
255
|
|
|
256
256
|
1. `agent start` — launch Chrome and persist session.
|
|
257
257
|
2. `agent elements` — discover what's on the page.
|
|
258
|
-
3. `agent
|
|
258
|
+
3. `agent navigate`, `agent click`, `agent type`, `agent select`, and related typed commands — execute actions using discovered selectors.
|
|
259
259
|
4. `agent content` — read page content after actions.
|
|
260
260
|
5. `agent memory-search` — reuse known selectors for repeated tasks.
|
|
261
261
|
6. `agent stop` — terminate when done.
|
|
@@ -265,7 +265,7 @@ agentic-browser memory:stats
|
|
|
265
265
|
- Exactly **one** managed session is supported at a time.
|
|
266
266
|
- Session state is persisted in `.agentic-browser/`.
|
|
267
267
|
- All commands print exactly one JSON line to `stdout`.
|
|
268
|
-
- `
|
|
268
|
+
- The typed `agent` commands are the preferred interface for LLMs. Use low-level `command:run` only when you need raw JSON payload control.
|
|
269
269
|
- Parse only `stdout` as result object and use exit code for success/failure.
|
|
270
270
|
|
|
271
271
|
## Programmatic API
|
package/dist/cli/index.mjs
CHANGED
|
@@ -64,7 +64,7 @@ async function agentStop(runtime) {
|
|
|
64
64
|
sessionId
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
async function
|
|
67
|
+
async function executeAgentCommand(runtime, input) {
|
|
68
68
|
const sessionId = requireSessionId(runtime);
|
|
69
69
|
await ensureReady(runtime, sessionId);
|
|
70
70
|
const attempt = () => runtime.api.executeCommand(sessionId, {
|
|
@@ -75,22 +75,75 @@ async function agentRun(runtime, input) {
|
|
|
75
75
|
try {
|
|
76
76
|
const first = await attempt();
|
|
77
77
|
if (first.resultStatus === "failed") throw new Error(first.resultMessage ?? "Command failed");
|
|
78
|
-
return
|
|
79
|
-
ok: true,
|
|
80
|
-
action: "run",
|
|
81
|
-
...first
|
|
82
|
-
};
|
|
78
|
+
return first;
|
|
83
79
|
} catch {
|
|
84
80
|
await runtime.api.restartSession(sessionId);
|
|
85
81
|
const second = await attempt();
|
|
86
82
|
if (second.resultStatus === "failed") throw new Error(second.resultMessage ?? "Command failed after retry");
|
|
87
|
-
return
|
|
88
|
-
ok: true,
|
|
89
|
-
action: "run",
|
|
90
|
-
...second
|
|
91
|
-
};
|
|
83
|
+
return second;
|
|
92
84
|
}
|
|
93
85
|
}
|
|
86
|
+
async function agentNavigate(runtime, input) {
|
|
87
|
+
const result = await executeAgentCommand(runtime, {
|
|
88
|
+
type: "navigate",
|
|
89
|
+
payload: { url: input.url }
|
|
90
|
+
});
|
|
91
|
+
let cookieBanner;
|
|
92
|
+
if (result.resultStatus === "success") try {
|
|
93
|
+
const sessionId = requireSessionId(runtime);
|
|
94
|
+
const dismissed = await runtime.api.dismissCookieBanner(sessionId);
|
|
95
|
+
if (dismissed.dismissed) cookieBanner = dismissed;
|
|
96
|
+
} catch {}
|
|
97
|
+
return {
|
|
98
|
+
ok: true,
|
|
99
|
+
action: "navigate",
|
|
100
|
+
...result,
|
|
101
|
+
cookieBanner
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function agentInteract(runtime, input) {
|
|
105
|
+
const result = await executeAgentCommand(runtime, {
|
|
106
|
+
type: "interact",
|
|
107
|
+
payload: input
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
ok: true,
|
|
111
|
+
action: input.action,
|
|
112
|
+
...result
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async function agentRestart(runtime) {
|
|
116
|
+
return {
|
|
117
|
+
ok: true,
|
|
118
|
+
action: "restart",
|
|
119
|
+
...await executeAgentCommand(runtime, {
|
|
120
|
+
type: "restart",
|
|
121
|
+
payload: {}
|
|
122
|
+
})
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
async function agentTerminate(runtime) {
|
|
126
|
+
const result = await executeAgentCommand(runtime, {
|
|
127
|
+
type: "terminate",
|
|
128
|
+
payload: {}
|
|
129
|
+
});
|
|
130
|
+
saveState(runtime, { sessionId: null });
|
|
131
|
+
return {
|
|
132
|
+
ok: true,
|
|
133
|
+
action: "terminate",
|
|
134
|
+
...result
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async function agentDismissCookies(runtime) {
|
|
138
|
+
const sessionId = requireSessionId(runtime);
|
|
139
|
+
await ensureReady(runtime, sessionId);
|
|
140
|
+
return {
|
|
141
|
+
ok: true,
|
|
142
|
+
action: "cookies",
|
|
143
|
+
sessionId,
|
|
144
|
+
...await runtime.api.dismissCookieBanner(sessionId)
|
|
145
|
+
};
|
|
146
|
+
}
|
|
94
147
|
async function agentContent(runtime, input) {
|
|
95
148
|
const sessionId = requireSessionId(runtime);
|
|
96
149
|
await ensureReady(runtime, sessionId);
|
|
@@ -243,6 +296,7 @@ async function main() {
|
|
|
243
296
|
const runtime = createCliRuntime();
|
|
244
297
|
const program = new Command();
|
|
245
298
|
program.name("agentic-browser").description("Agentic browser CLI");
|
|
299
|
+
const collect = (value, previous = []) => [...previous, value];
|
|
246
300
|
program.command("session:start").option("--cdp-url <url>", "connect to existing Chrome via CDP endpoint URL").option("--user-profile <path>", "use 'default' for system Chrome profile or an absolute path").option("--headless", "run Chrome in headless mode (no visible window)").option("--user-agent <string>", "override the browser user-agent string").action(async (options) => {
|
|
247
301
|
if (options.cdpUrl) runtime.context.config.cdpUrl = options.cdpUrl;
|
|
248
302
|
if (options.userProfile) runtime.context.config.userProfileDir = options.userProfile === "true" || options.userProfile === "default" ? "default" : options.userProfile;
|
|
@@ -328,13 +382,109 @@ async function main() {
|
|
|
328
382
|
const result = await agentStop(runtime);
|
|
329
383
|
console.log(JSON.stringify(result));
|
|
330
384
|
});
|
|
331
|
-
agent.command("
|
|
332
|
-
const result = await
|
|
333
|
-
|
|
334
|
-
|
|
385
|
+
agent.command("navigate").argument("<url>").action(async (url) => {
|
|
386
|
+
const result = await agentNavigate(runtime, { url });
|
|
387
|
+
console.log(JSON.stringify(result));
|
|
388
|
+
});
|
|
389
|
+
agent.command("click").argument("<selector>").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (selector, options) => {
|
|
390
|
+
const result = await agentInteract(runtime, {
|
|
391
|
+
action: "click",
|
|
392
|
+
selector,
|
|
393
|
+
fallbackSelectors: options.fallback
|
|
394
|
+
});
|
|
395
|
+
console.log(JSON.stringify(result));
|
|
396
|
+
});
|
|
397
|
+
agent.command("type").argument("<selector>").argument("<text>").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (selector, text, options) => {
|
|
398
|
+
const result = await agentInteract(runtime, {
|
|
399
|
+
action: "type",
|
|
400
|
+
selector,
|
|
401
|
+
text,
|
|
402
|
+
fallbackSelectors: options.fallback
|
|
335
403
|
});
|
|
336
404
|
console.log(JSON.stringify(result));
|
|
337
405
|
});
|
|
406
|
+
agent.command("press").argument("<key>").action(async (key) => {
|
|
407
|
+
const result = await agentInteract(runtime, {
|
|
408
|
+
action: "press",
|
|
409
|
+
key
|
|
410
|
+
});
|
|
411
|
+
console.log(JSON.stringify(result));
|
|
412
|
+
});
|
|
413
|
+
agent.command("wait").argument("<selector>").option("--timeout <ms>", "timeout in milliseconds", "2000").action(async (selector, options) => {
|
|
414
|
+
const result = await agentInteract(runtime, {
|
|
415
|
+
action: "waitFor",
|
|
416
|
+
selector,
|
|
417
|
+
timeoutMs: Number.parseInt(options.timeout, 10)
|
|
418
|
+
});
|
|
419
|
+
console.log(JSON.stringify(result));
|
|
420
|
+
});
|
|
421
|
+
agent.command("hover").argument("<selector>").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (selector, options) => {
|
|
422
|
+
const result = await agentInteract(runtime, {
|
|
423
|
+
action: "hover",
|
|
424
|
+
selector,
|
|
425
|
+
fallbackSelectors: options.fallback
|
|
426
|
+
});
|
|
427
|
+
console.log(JSON.stringify(result));
|
|
428
|
+
});
|
|
429
|
+
agent.command("select").argument("<selector>").argument("<value>").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (selector, value, options) => {
|
|
430
|
+
const result = await agentInteract(runtime, {
|
|
431
|
+
action: "select",
|
|
432
|
+
selector,
|
|
433
|
+
value,
|
|
434
|
+
fallbackSelectors: options.fallback
|
|
435
|
+
});
|
|
436
|
+
console.log(JSON.stringify(result));
|
|
437
|
+
});
|
|
438
|
+
agent.command("toggle").argument("<selector>").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (selector, options) => {
|
|
439
|
+
const result = await agentInteract(runtime, {
|
|
440
|
+
action: "toggle",
|
|
441
|
+
selector,
|
|
442
|
+
fallbackSelectors: options.fallback
|
|
443
|
+
});
|
|
444
|
+
console.log(JSON.stringify(result));
|
|
445
|
+
});
|
|
446
|
+
agent.command("scroll").option("--x <pixels>", "horizontal scroll delta", "0").option("--y <pixels>", "vertical scroll delta", "0").option("--selector <selector>", "scroll a specific element instead of the page").option("--fallback <selector>", "backup CSS selector", collect, []).action(async (options) => {
|
|
447
|
+
const result = await agentInteract(runtime, {
|
|
448
|
+
action: "scroll",
|
|
449
|
+
selector: options.selector,
|
|
450
|
+
fallbackSelectors: options.fallback,
|
|
451
|
+
scrollX: Number.parseInt(options.x, 10),
|
|
452
|
+
scrollY: Number.parseInt(options.y, 10)
|
|
453
|
+
});
|
|
454
|
+
console.log(JSON.stringify(result));
|
|
455
|
+
});
|
|
456
|
+
agent.command("back").action(async () => {
|
|
457
|
+
const result = await agentInteract(runtime, { action: "goBack" });
|
|
458
|
+
console.log(JSON.stringify(result));
|
|
459
|
+
});
|
|
460
|
+
agent.command("forward").action(async () => {
|
|
461
|
+
const result = await agentInteract(runtime, { action: "goForward" });
|
|
462
|
+
console.log(JSON.stringify(result));
|
|
463
|
+
});
|
|
464
|
+
agent.command("refresh").action(async () => {
|
|
465
|
+
const result = await agentInteract(runtime, { action: "refresh" });
|
|
466
|
+
console.log(JSON.stringify(result));
|
|
467
|
+
});
|
|
468
|
+
agent.command("dialog").option("--dismiss", "dismiss the current dialog").option("--value <text>", "prompt response text").action(async (options) => {
|
|
469
|
+
const result = await agentInteract(runtime, {
|
|
470
|
+
action: "dialog",
|
|
471
|
+
text: options.dismiss ? "dismiss" : void 0,
|
|
472
|
+
value: options.value
|
|
473
|
+
});
|
|
474
|
+
console.log(JSON.stringify(result));
|
|
475
|
+
});
|
|
476
|
+
agent.command("cookies").action(async () => {
|
|
477
|
+
const result = await agentDismissCookies(runtime);
|
|
478
|
+
console.log(JSON.stringify(result));
|
|
479
|
+
});
|
|
480
|
+
agent.command("restart").action(async () => {
|
|
481
|
+
const result = await agentRestart(runtime);
|
|
482
|
+
console.log(JSON.stringify(result));
|
|
483
|
+
});
|
|
484
|
+
agent.command("terminate").action(async () => {
|
|
485
|
+
const result = await agentTerminate(runtime);
|
|
486
|
+
console.log(JSON.stringify(result));
|
|
487
|
+
});
|
|
338
488
|
agent.command("content").option("--mode <mode>", "title|text|html|a11y", "text").option("--selector <selector>", "optional CSS selector").action(async (options) => {
|
|
339
489
|
const result = await agentContent(runtime, options);
|
|
340
490
|
console.log(JSON.stringify(result));
|