@different-ai/opencode-browser 2.0.0 → 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/package.json +1 -1
- package/src/plugin.ts +15 -4
package/package.json
CHANGED
package/src/plugin.ts
CHANGED
|
@@ -19,9 +19,11 @@ import { join } from "path";
|
|
|
19
19
|
const WS_PORT = 19222;
|
|
20
20
|
const BASE_DIR = join(homedir(), ".opencode-browser");
|
|
21
21
|
const LOCK_FILE = join(BASE_DIR, "lock.json");
|
|
22
|
+
const SCREENSHOTS_DIR = join(BASE_DIR, "screenshots");
|
|
22
23
|
|
|
23
|
-
// Ensure
|
|
24
|
+
// Ensure directories exist
|
|
24
25
|
mkdirSync(BASE_DIR, { recursive: true });
|
|
26
|
+
mkdirSync(SCREENSHOTS_DIR, { recursive: true });
|
|
25
27
|
|
|
26
28
|
// Session state
|
|
27
29
|
const sessionId = Math.random().toString(36).slice(2);
|
|
@@ -376,17 +378,26 @@ export const BrowserPlugin: Plugin = async (ctx) => {
|
|
|
376
378
|
}),
|
|
377
379
|
|
|
378
380
|
browser_screenshot: tool({
|
|
379
|
-
description: "Take a screenshot of the current page",
|
|
381
|
+
description: "Take a screenshot of the current page. Saves to ~/.opencode-browser/screenshots/ and returns the file path.",
|
|
380
382
|
args: {
|
|
381
383
|
tabId: tool.schema.optional(tool.schema.number({ description: "Optional tab ID" })),
|
|
384
|
+
name: tool.schema.optional(tool.schema.string({ description: "Optional name for the screenshot file (without extension)" })),
|
|
382
385
|
},
|
|
383
386
|
async execute(args) {
|
|
384
387
|
const result = await executeCommand("screenshot", args);
|
|
385
|
-
|
|
388
|
+
|
|
386
389
|
if (result && result.startsWith("data:image")) {
|
|
390
|
+
// Extract base64 data and save to file
|
|
387
391
|
const base64Data = result.replace(/^data:image\/\w+;base64,/, "");
|
|
388
|
-
|
|
392
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
393
|
+
const filename = args.name ? `${args.name}.png` : `screenshot-${timestamp}.png`;
|
|
394
|
+
const filepath = join(SCREENSHOTS_DIR, filename);
|
|
395
|
+
|
|
396
|
+
writeFileSync(filepath, Buffer.from(base64Data, "base64"));
|
|
397
|
+
|
|
398
|
+
return `Screenshot saved: ${filepath}`;
|
|
389
399
|
}
|
|
400
|
+
|
|
390
401
|
return result;
|
|
391
402
|
},
|
|
392
403
|
}),
|