agentic-browser 2.3.0 → 2.5.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 +1 -1
- package/README.md +4 -1
- package/dist/cli/index.d.mts +2 -0
- package/dist/cli/index.mjs +1 -1
- package/dist/index.d.mts +928 -0
- package/dist/index.mjs +1 -1
- package/dist/mcp/index.d.mts +5 -0
- package/dist/mcp/index.mjs +59 -3
- package/dist/{runtime-BCGndjhR.mjs → runtime-C3Y-UgC1.mjs} +519 -51
- package/package.json +30 -4
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { i as createMockAgenticBrowserCore, n as createAgenticBrowserCore, t as AgenticBrowserCore } from "./runtime-
|
|
2
|
+
import { i as createMockAgenticBrowserCore, n as createAgenticBrowserCore, t as AgenticBrowserCore } from "./runtime-C3Y-UgC1.mjs";
|
|
3
3
|
export { AgenticBrowserCore, createAgenticBrowserCore, createMockAgenticBrowserCore };
|
package/dist/mcp/index.mjs
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { n as createAgenticBrowserCore } from "../runtime-
|
|
2
|
+
import { n as createAgenticBrowserCore } from "../runtime-C3Y-UgC1.mjs";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
3
6
|
import { z } from "zod";
|
|
4
7
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -199,6 +202,29 @@ function compactMemoryResults(results) {
|
|
|
199
202
|
}
|
|
200
203
|
//#endregion
|
|
201
204
|
//#region src/mcp/index.ts
|
|
205
|
+
function readPackageVersion() {
|
|
206
|
+
try {
|
|
207
|
+
const dir = dirname(fileURLToPath(import.meta.url));
|
|
208
|
+
for (const rel of ["../../package.json", "../package.json"]) try {
|
|
209
|
+
const pkg = JSON.parse(readFileSync(join(dir, rel), "utf8"));
|
|
210
|
+
if (pkg.version) return pkg.version;
|
|
211
|
+
} catch {}
|
|
212
|
+
} catch {}
|
|
213
|
+
return "0.0.0";
|
|
214
|
+
}
|
|
215
|
+
function classifyError(message) {
|
|
216
|
+
const lower = message.toLowerCase();
|
|
217
|
+
if (lower.includes("not found") || lower.includes("no element")) return "SELECTOR_NOT_FOUND";
|
|
218
|
+
if (lower.includes("covered") || lower.includes("overlay")) return "ELEMENT_COVERED";
|
|
219
|
+
if (lower.includes("not editable") || lower.includes("readonly")) return "ELEMENT_NOT_EDITABLE";
|
|
220
|
+
if (lower.includes("navigation failed")) return "NAVIGATION_FAILED";
|
|
221
|
+
if (lower.includes("navigation") && lower.includes("timeout")) return "NAVIGATION_TIMEOUT";
|
|
222
|
+
if (lower.includes("cdp connection") || lower.includes("websocket")) return "CDP_DISCONNECTED";
|
|
223
|
+
if (lower.includes("session") && (lower.includes("dead") || lower.includes("terminated"))) return "SESSION_DEAD";
|
|
224
|
+
if (lower.includes("dialog")) return "DIALOG_BLOCKING";
|
|
225
|
+
if (lower.includes("timeout")) return "TIMEOUT";
|
|
226
|
+
return "UNKNOWN";
|
|
227
|
+
}
|
|
202
228
|
let core;
|
|
203
229
|
let activeSessionId;
|
|
204
230
|
const DEFAULT_MCP_MAX_CHARS = {
|
|
@@ -227,7 +253,7 @@ async function resolveSession(sessionId) {
|
|
|
227
253
|
}
|
|
228
254
|
const server = new McpServer({
|
|
229
255
|
name: "agentic-browser",
|
|
230
|
-
version:
|
|
256
|
+
version: readPackageVersion()
|
|
231
257
|
});
|
|
232
258
|
server.tool("browser_start_session", "Start a new Chrome browser session (or return the existing one if healthy). Sessions auto-start when you call any other browser tool, so you rarely need to call this explicitly. Use this to force a fresh session after stopping the previous one.", {}, async () => {
|
|
233
259
|
const session = await getCore().startSession();
|
|
@@ -254,11 +280,17 @@ server.tool("browser_navigate", "Navigate the browser to a URL. A session is aut
|
|
|
254
280
|
const dismissed = await getCore().dismissCookieBanner(sid);
|
|
255
281
|
if (dismissed.dismissed) cookieBanner = dismissed;
|
|
256
282
|
} catch {}
|
|
283
|
+
let currentUrl;
|
|
284
|
+
try {
|
|
285
|
+
currentUrl = await getCore().getCurrentUrl(sid);
|
|
286
|
+
} catch {}
|
|
257
287
|
const compact = {
|
|
258
288
|
resultStatus: result.resultStatus,
|
|
259
289
|
resultMessage: result.resultMessage,
|
|
290
|
+
currentUrl,
|
|
260
291
|
cookieBanner
|
|
261
292
|
};
|
|
293
|
+
if (result.resultStatus === "failed") compact.errorCode = classifyError(result.resultMessage ?? "");
|
|
262
294
|
return { content: [{
|
|
263
295
|
type: "text",
|
|
264
296
|
text: JSON.stringify(compact)
|
|
@@ -305,10 +337,16 @@ server.tool("browser_interact", "Interact with a page element or perform browser
|
|
|
305
337
|
type: "interact",
|
|
306
338
|
payload
|
|
307
339
|
});
|
|
340
|
+
let currentUrl;
|
|
341
|
+
try {
|
|
342
|
+
currentUrl = await getCore().getCurrentUrl(sid);
|
|
343
|
+
} catch {}
|
|
308
344
|
const compact = {
|
|
309
345
|
resultStatus: result.resultStatus,
|
|
310
|
-
resultMessage: result.resultMessage
|
|
346
|
+
resultMessage: result.resultMessage,
|
|
347
|
+
currentUrl
|
|
311
348
|
};
|
|
349
|
+
if (result.resultStatus === "failed") compact.errorCode = classifyError(result.resultMessage ?? "");
|
|
312
350
|
return { content: [{
|
|
313
351
|
type: "text",
|
|
314
352
|
text: JSON.stringify(compact)
|
|
@@ -392,6 +430,24 @@ server.tool("browser_dismiss_cookies", "Dismiss cookie consent banners on the cu
|
|
|
392
430
|
text: JSON.stringify(result)
|
|
393
431
|
}] };
|
|
394
432
|
});
|
|
433
|
+
server.tool("browser_screenshot", "Capture a screenshot of the current page. Returns a base64-encoded image. Useful for visual verification, debugging element discovery failures, or when you need to see what the page looks like. A session is auto-started if needed.", {
|
|
434
|
+
format: z.enum(["jpeg", "png"]).default("jpeg").describe("Image format (jpeg is smaller, png is lossless)"),
|
|
435
|
+
quality: z.number().optional().describe("JPEG quality 0-100 (default 60, ignored for png)"),
|
|
436
|
+
fullPage: z.boolean().default(false).describe("Capture the full scrollable page instead of just the viewport"),
|
|
437
|
+
sessionId: z.string().optional().describe("Session ID (auto-resolved if omitted)")
|
|
438
|
+
}, async ({ format, quality, fullPage, sessionId }) => {
|
|
439
|
+
const sid = await resolveSession(sessionId);
|
|
440
|
+
const result = await getCore().screenshot(sid, {
|
|
441
|
+
format,
|
|
442
|
+
quality,
|
|
443
|
+
fullPage
|
|
444
|
+
});
|
|
445
|
+
return { content: [{
|
|
446
|
+
type: "image",
|
|
447
|
+
data: result.data,
|
|
448
|
+
mimeType: result.mimeType
|
|
449
|
+
}] };
|
|
450
|
+
});
|
|
395
451
|
server.tool("browser_stop_session", "Stop the browser session and terminate Chrome. The next browser tool call will auto-start a fresh session.", { sessionId: z.string().optional().describe("Session ID (uses active session if omitted)") }, async ({ sessionId }) => {
|
|
396
452
|
const sid = sessionId ?? activeSessionId;
|
|
397
453
|
if (!sid) return { content: [{
|