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.

fix(agent): gate form submission by effect rather than by action name

Shahriar41b0e0ff0493
diff --git a/lib/actions/page/click-element.ts b/lib/actions/page/click-element.ts
index 3c2efe9..f049a42 100644
--- a/lib/actions/page/click-element.ts
+++ b/lib/actions/page/click-element.ts
@@ -16,12 +16,16 @@ export const clickElement = defineAction({
el.focus({ preventScroll: true });
} catch {
}
+ const submits =
+ !!el.closest('form') &&
+ ((el instanceof HTMLButtonElement && el.type === 'submit') ||
+ (el instanceof HTMLInputElement && (el.type === 'submit' || el.type === 'image')));
const init = { bubbles: true, cancelable: true, composed: true };
el.dispatchEvent(new PointerEvent('pointerdown', init));
el.dispatchEvent(new MouseEvent('mousedown', init));
el.dispatchEvent(new PointerEvent('pointerup', init));
el.dispatchEvent(new MouseEvent('mouseup', init));
el.click();
- return describeElement(el);
+ return { ...describeElement(el), submits };
},
});
diff --git a/mcp/src/agent/effects.ts b/mcp/src/agent/effects.ts
new file mode 100644
index 0000000..e7c767f
--- /dev/null
+++ b/mcp/src/agent/effects.ts
@@ -0,0 +1,14 @@
+export const SUBMIT_ACTION = 'page.submitForm';
+
+export function submitsForm(action: string, input: unknown): boolean {
+ if (action === SUBMIT_ACTION) return true;
+ const args = (input ?? {}) as { pressEnter?: unknown; key?: unknown };
+ if (action === 'page.fillInput') return args.pressEnter === true;
+ if (action === 'page.pressKey') return args.key === 'Enter';
+ return false;
+}
+
+export function needsApproval(requireApproval: readonly string[], action: string, input: unknown): boolean {
+ if (requireApproval.includes(action)) return true;
+ return requireApproval.includes(SUBMIT_ACTION) && submitsForm(action, input);
+}
diff --git a/mcp/src/agent/service.ts b/mcp/src/agent/service.ts
index 4597d7a..cea75cf 100644
--- a/mcp/src/agent/service.ts
+++ b/mcp/src/agent/service.ts
@@ -12,6 +12,7 @@ import {
import { SAVE_SITE_MAP_ACTION, SITE_MAPPER_SKILL, validateSiteMapReport } from '@/lib/skills/site-map';
import { log } from '../log';
import { readAgentConfig, siteMapSettings, type AgentConfig } from './config';
+import { needsApproval } from './effects';
import { gateMappingInvoke, noteMappingResult, type MapRun } from './mapping';
import { buildSystemPrompt } from './prompt';
import { RunError, runInstruction } from './runner';
@@ -102,7 +103,7 @@ export class AgentSession {
return result;
}
- if (run.config.requireApproval.includes(action)) {
+ if (needsApproval(run.config.requireApproval, action, input)) {
emit({ kind: 'approval', toolId, action, input });
if (!(await this.awaitDecision(run, toolId))) {
emit({ kind: 'toolResult', toolId, ok: false, summary: 'declined by the user' });
@@ -461,9 +462,11 @@ function summarize(input: unknown, result: ActionResult): string {
return clip(`image ${shot.width ?? '?'}×${shot.height ?? '?'}${saved}`);
}
+ const submits = (result.data as { submits?: unknown } | null)?.submits === true ? ' — submits a form' : '';
+
const target = (input as { target?: { text?: string; selector?: string } } | undefined)?.target;
- if (target?.text) return clip(`“${target.text}”`);
- if (target?.selector) return clip(target.selector);
+ if (target?.text) return clip(`“${target.text}”${submits}`);
+ if (target?.selector) return clip(`${target.selector}${submits}`);
const data = result.data as Record<string, unknown> | null;
for (const key of ['navigatedTo', 'navigatingTo', 'url', 'performed', 'value']) {