aboutsummaryrefslogtreecommitdiff
path: root/src/tools.ts
diff options
context:
space:
mode:
authoramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 11:40:20 +0530
committeramankumarsingh77 <amankumarsingh7702@gmal.com>2026-05-02 11:40:20 +0530
commitfa54f769aad7bc3b6b05cf877cc5adda879721be (patch)
tree42a8861cb4e50f54beac37b2fc7de33b19872d07 /src/tools.ts
parentb77c5ec30d37f214fe469791f814da8329ef4a77 (diff)
perf: v0.2.0 — event-based waitForLoad, fast ensureAlive, JPEG screenshots, page info caching
5 performance optimizations (14-36% faster end-to-end, output quality unchanged): - fast ensureAlive(): WS state check instead of CDP roundtrip (96% faster per-call) - event-based waitForLoad(): CDP load events instead of 300ms polling (99.5% faster for loaded tabs) - JPEG screenshot support: 29-49% smaller files, faster CDP transfer - page info caching: 1s TTL eliminates redundant evaluateJS calls - parallel domain enables: Promise.all instead of sequential await in switchTab() Benchmark: 3622ms vs 4243ms baseline on 3-tab navigation + screenshot task.
Diffstat (limited to 'src/tools.ts')
-rw-r--r--src/tools.ts15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/tools.ts b/src/tools.ts
index 822854c..323f327 100644
--- a/src/tools.ts
+++ b/src/tools.ts
@@ -542,8 +542,8 @@ export function registerTools(pi: ExtensionAPI, daemon: BrowserDaemon): void {
name: "browser_screenshot",
label: "Browser Screenshot",
description:
- "Capture a PNG screenshot of the current page. Use this BEFORE interactions to find targets, and AFTER to verify results. This is the primary visual feedback mechanism.",
- promptSnippet: "Capture a screenshot of the current page (PNG)",
+ "Capture a PNG or JPEG screenshot of the current page. Use this BEFORE interactions to find targets, and AFTER to verify results. JPEG (quality 80) is 2-5x smaller for complex pages — faster transfer and lower LLM context cost.",
+ promptSnippet: "Capture a screenshot of the current page (PNG or JPEG)",
promptGuidelines: [
"Use browser_screenshot as your FIRST step when exploring a page — it shows you what's visible.",
"After every browser_click, browser_type, browser_scroll, or browser_navigate, capture a screenshot to VERIFY the action worked.",
@@ -552,15 +552,20 @@ export function registerTools(pi: ExtensionAPI, daemon: BrowserDaemon): void {
],
parameters: Type.Object({
fullPage: Type.Optional(Type.Boolean({ description: "Capture the full scrollable page (not just viewport). Default: false" })),
+ format: Type.Optional(Type.String({ description: "Image format: 'png' or 'jpeg'. Default: 'png'" })),
+ quality: Type.Optional(Type.Number({ description: "JPEG quality 1-100. Default: 80. Ignored for PNG." })),
}),
async execute(_id, params) {
try {
await daemon.ensureAlive();
const path = nextScreenshotPath();
- await daemon.captureScreenshot(path, params.fullPage === true);
+ const format = (params.format === "jpeg" ? "jpeg" : "png") as "png" | "jpeg";
+ const quality = typeof params.quality === "number" ? params.quality : 80;
+ await daemon.captureScreenshot(path, params.fullPage === true, format, quality);
+ const fmtLabel = format === "jpeg" ? ` (JPEG q${quality})` : "";
return {
- content: [{ type: "text" as const, text: `Screenshot saved: ${path}${params.fullPage ? " (full page)" : ""}` }],
- details: { path },
+ content: [{ type: "text" as const, text: `Screenshot saved: ${path}${params.fullPage ? " (full page)" : ""}${fmtLabel}` }],
+ details: { path, format, quality },
};
} catch (err) {
return {