Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

feat(actions): add screenshot and stored-file actions

Shahriaree60cddd62bf
diff --git a/lib/actions/page/attach-file.ts b/lib/actions/page/attach-file.ts
new file mode 100644
index 0000000..ed678d7
--- /dev/null
+++ b/lib/actions/page/attach-file.ts
@@ -0,0 +1,43 @@
+import { z } from 'zod';
+import { ActionError, defineAction } from '../core';
+import { describeElement, resolveTarget, targetSchema } from './dom';
+
+export const attachFile = defineAction({
+ name: 'page.attachFile',
+ description: 'Attach a stored VoiceLink file (by id, from page.listFiles) to a file input on the page.',
+ input: z.object({
+ fileId: z.string().describe('Id of a stored file, taken from page.listFiles.'),
+ target: targetSchema.describe('The file input (<input type="file">) to attach the file to.'),
+ // The extension fills these in after reading the stored bytes; leave them unset when calling.
+ name: z.string().optional().describe('Internal: original filename. The extension fills this in.'),
+ mime: z.string().optional().describe('Internal: file MIME type. The extension fills this in.'),
+ content: z.string().optional().describe('Internal: base64 file bytes. The extension fills this in.'),
+ }),
+ execute({ target, name, mime, content }) {
+ if (!content) {
+ throw new ActionError('No file bytes were supplied — call with a valid fileId.', 'INVALID_INPUT');
+ }
+ // File inputs are commonly hidden behind a styled button, so look past the visibility filter.
+ const el = resolveTarget(target, { includeHidden: true });
+ if (!(el instanceof HTMLInputElement) || el.type !== 'file') {
+ throw new ActionError(`<${el.tagName.toLowerCase()}> is not a file input`, 'INVALID_TARGET');
+ }
+
+ const binary = atob(content);
+ const bytes = new Uint8Array(binary.length);
+ for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
+
+ const file = new File([bytes], name || 'file', { type: mime || 'application/octet-stream' });
+ const transfer = new DataTransfer();
+ transfer.items.add(file);
+ // A FileList cannot be built directly; DataTransfer yields one. Assign it through the native
+ // prototype setter (as fill-input.ts does for value), then fire the events sites listen for.
+ // Note: this cannot open the OS picker, and an uploader that only trusts a real user gesture
+ // may ignore the synthetic change — there is no way around a genuinely gesture-gated field.
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'files')!.set!.call(el, transfer.files);
+ el.dispatchEvent(new Event('input', { bubbles: true }));
+ el.dispatchEvent(new Event('change', { bubbles: true }));
+
+ return { attached: true, name: file.name, size: bytes.length, mime: file.type, element: describeElement(el) };
+ },
+});
diff --git a/lib/actions/page/list-files.ts b/lib/actions/page/list-files.ts
new file mode 100644
index 0000000..fd870a2
--- /dev/null
+++ b/lib/actions/page/list-files.ts
@@ -0,0 +1,18 @@
+import { z } from 'zod';
+import { ActionError, defineAction } from '../core';
+
+export const listFiles = defineAction({
+ name: 'page.listFiles',
+ description: 'List the files the user has stored in VoiceLink, with their AI-generated summaries.',
+ input: z.object({
+ nameContains: z
+ .string()
+ .optional()
+ .describe('Only return files whose name contains this text (case-insensitive).'),
+ }),
+ execute() {
+ // Resolved by the VoiceLink extension background, which reads extension storage a page
+ // cannot reach (see lib/bridge/invoke.ts). The in-page path is never taken via the harness.
+ throw new ActionError('page.listFiles is resolved by the VoiceLink extension, not in the page', 'UNSUPPORTED');
+ },
+});
diff --git a/lib/actions/page/screenshot.ts b/lib/actions/page/screenshot.ts
new file mode 100644
index 0000000..e61bf6e
--- /dev/null
+++ b/lib/actions/page/screenshot.ts
@@ -0,0 +1,87 @@
+import { z } from 'zod';
+import { ActionError, defineAction } from '../core';
+import { documentBounds, resolveTarget, targetSchema } from './dom';
+
+/**
+ * Screenshotting is a cross-context capability, like `page.navigate`: a content script cannot
+ * call `chrome.tabs.captureVisibleTab` (background-only) nor write files (daemon-only). So this
+ * action's `execute()` does the one part the page *can* do — measure — and returns a capture
+ * *plan*. The background worker reads the plan, scrolls + captures + stitches the pixels
+ * (`lib/bridge/screenshot.ts`, routed from `lib/bridge/invoke.ts`), and the daemon saves the
+ * file. Running this action in-page has no side effect; it never touches the pixels itself.
+ */
+export const screenshot = defineAction({
+ name: 'page.screenshot',
+ description:
+ 'Capture the tab as a PNG/JPEG image — the full scroll view, the current viewport, or a single targeted element. Optionally save it under ~/voicelink/screenshot/.',
+ input: z.object({
+ target: targetSchema
+ .optional()
+ .describe('Capture only this element’s box (a specific block). When set, fullPage is ignored.'),
+ fullPage: z
+ .boolean()
+ .default(true)
+ .describe('With no target: true captures the entire scroll view, false only the current viewport.'),
+ format: z
+ .enum(['png', 'jpeg'])
+ .default('png')
+ .describe('Image format. PNG is lossless; JPEG is smaller with slight artifacts and no transparency.'),
+ quality: z
+ .number()
+ .int()
+ .min(1)
+ .max(100)
+ .optional()
+ .describe('JPEG quality, 1–100. Only valid when format is "jpeg".'),
+ maxLongSide: z
+ .number()
+ .int()
+ .positive()
+ .default(4000)
+ .describe('Downscale the result so its longest side is at most this many pixels.'),
+ save: z
+ .boolean()
+ .default(false)
+ .describe('Save the image to ~/voicelink/screenshot/ (written by the local VoiceLink daemon).'),
+ filename: z
+ .string()
+ .optional()
+ .describe('Base filename when saving; defaults to screenshot-<timestamp>.<ext>. Sanitized before use.'),
+ }),
+ execute({ target, fullPage, format, quality, maxLongSide }) {
+ // Validate what the schema can't express (no .refine — it wouldn't survive z.toJSONSchema).
+ if (quality !== undefined && format !== 'jpeg') {
+ throw new ActionError('"quality" only applies when format is "jpeg"', 'INVALID_INPUT');
+ }
+
+ const dpr = window.devicePixelRatio || 1;
+ const viewport = { w: window.innerWidth, h: window.innerHeight };
+ const root = document.documentElement;
+ const page = { w: root.scrollWidth, h: root.scrollHeight };
+
+ // The region to capture, in *document* coordinates. The background tiles the viewport across
+ // it, so a region larger than the viewport (a tall page or a big element) is expected.
+ let mode: 'fullPage' | 'viewport' | 'element';
+ let region: { x: number; y: number; w: number; h: number };
+ if (target) {
+ const bounds = documentBounds(resolveTarget(target));
+ if (bounds.width === 0 || bounds.height === 0) {
+ throw new ActionError('Target element has no visible box to capture', 'INVALID_TARGET');
+ }
+ mode = 'element';
+ region = { x: bounds.x, y: bounds.y, w: bounds.width, h: bounds.height };
+ } else if (fullPage) {
+ mode = 'fullPage';
+ region = { x: 0, y: 0, w: page.w, h: page.h };
+ } else {
+ mode = 'viewport';
+ region = { x: Math.round(window.scrollX), y: Math.round(window.scrollY), w: viewport.w, h: viewport.h };
+ }
+
+ // The current scroll, so the background can put the page back where it found it.
+ const scroll = { x: Math.round(window.scrollX), y: Math.round(window.scrollY) };
+
+ // The plan crosses sendMessage, so it stays small and JSON-serializable (no pixels here).
+ return { mode, dpr, viewport, page, region, scroll, format, quality, maxLongSide };
+ },
+});