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.
TypeScript agentic-browseragentic-browsingagy-cliaiai-agentai-browser-extensionai-toolsbrave-extensionbrowser-agentbrowser-automationbrowser-extensionbrowser-usebrowserskillchrome-extensionclaude-codecodexfirefox-addonmcp-servernanobrowserweb-automation
feat(extension): agent state bridge, side panel opener and context menu
Shahriar3fd8bbadd203
diff --git a/entrypoints/background.ts b/entrypoints/background.tsindex c5da0f9..86df88d 100644--- a/entrypoints/background.ts+++ b/entrypoints/background.ts@@ -2,6 +2,7 @@ import { failure, isBridgeRequest, success } from '@/lib/actions/protocol';import { describeActions } from '@/lib/actions/registry';import { injectContentScript } from '@/lib/actions/client';import { invokeForHarness } from '@/lib/bridge/invoke';+import { serveDebuggerEvents } from '@/lib/bridge/cdp';import { analyzeStoredFile } from '@/lib/bridge/file-store';import { pushSkill, removeSkill, resyncSkills } from '@/lib/bridge/skill-store';import { nameStoredSession } from '@/lib/bridge/session-store';@@ -9,9 +10,24 @@ import { analyzeStoredRecording, resumePendingAnalyses } from '@/lib/bridge/recoimport { ingestSample, monitorsForTab, serveMonitor } from '@/lib/bridge/monitor';import { appendEvents, recordingStateFor, serveRecorder } from '@/lib/bridge/recorder';import { serveRunPorts } from '@/lib/bridge/run-port';-import { RECONNECT_ALARM, connectDaemon, disconnectDaemon, onWelcome, pairDaemon } from '@/lib/bridge/socket';+import { openSidePanel } from '@/lib/bridge/side-panel';+import { isAgentKind } from '@/lib/agents/catalog';+import {+ RECONNECT_ALARM,+ chooseAgent,+ connectDaemon,+ disconnectDaemon,+ onWelcome,+ pairDaemon,+ readAgentState,+ setUpAgent,+} from '@/lib/bridge/socket';++const OPEN_PANEL_MENU = 'open-side-panel';export default defineBackground(() => {+ serveDebuggerEvents();+browser.runtime.onMessage.addListener((message, sender, sendResponse) => {if (!isBridgeRequest(message)) return;if (message.op === 'describe') {@@ -71,6 +87,24 @@ export default defineBackground(() => {.catch(() => sendResponse(success({ monitors: [] })));return true;}+ if (message.op === 'agentState') {+ readAgentState(message.refresh === true)+ .then(sendResponse)+ .catch((error) => sendResponse(failure('BRIDGE_ERROR', String(error))));+ return true;+ }+ if (message.op === 'setAgent' && isAgentKind(message.agent)) {+ chooseAgent(message.agent)+ .then(sendResponse)+ .catch((error) => sendResponse(failure('BRIDGE_ERROR', String(error))));+ return true;+ }+ if (message.op === 'grantAgent' && isAgentKind(message.agent)) {+ setUpAgent(message.agent)+ .then(sendResponse)+ .catch((error) => sendResponse(failure('BRIDGE_ERROR', String(error))));+ return true;+ }if (message.op === 'pair' && typeof message.token === 'string') {pairDaemon(message.token).then((result) =>@@ -88,7 +122,7 @@ export default defineBackground(() => {sendResponse(failure('INVALID_REQUEST',- 'Expected {op:"describe"|"invoke"|"analyzeFile"|"saveSkill"|"removeSkill"|"nameSession"|"recordEvents"|"recordingState"|"analyzeRecording"|"monitorSample"|"monitorState"|"pair"|"disconnect"}',+ 'Expected {op:"describe"|"invoke"|"analyzeFile"|"saveSkill"|"removeSkill"|"nameSession"|"recordEvents"|"recordingState"|"analyzeRecording"|"monitorSample"|"monitorState"|"agentState"|"setAgent"|"grantAgent"|"pair"|"disconnect"}',),);return;@@ -102,6 +136,17 @@ export default defineBackground(() => {});});+ void browser.contextMenus+ .removeAll()+ .then(() =>+ browser.contextMenus.create({ id: OPEN_PANEL_MENU, title: 'Open Browsentic', contexts: ['all'] }),+ );++ browser.contextMenus.onClicked.addListener((info, tab) => {+ if (info.menuItemId !== OPEN_PANEL_MENU || tab?.windowId == null) return;+ void openSidePanel(tab.windowId);+ });+serveRecorder();serveMonitor();serveRunPorts();diff --git a/lib/bridge/run-port.ts b/lib/bridge/run-port.tsindex 593bb4e..5a3af13 100644--- a/lib/bridge/run-port.ts+++ b/lib/bridge/run-port.ts@@ -45,7 +45,7 @@ const CANCEL_CONFIRM_MS = 4_000;export type RunCommand =| { op: 'instruct'; text: string; context?: RunContext }| { op: 'cancel' }- | { op: 'decision'; toolId: string; allow: boolean }+ | { op: 'decision'; toolId: string; allow: boolean; remember?: boolean }| { op: 'reset' }| { op: 'activateMap'; stagingId: string; exactHost?: boolean }| { op: 'discardMap'; stagingId: string }@@ -150,7 +150,7 @@ function handle(command: RunCommand): void {stopRun();return;case 'decision':- if (activeRunId) sendDecision(activeRunId, command.toolId, command.allow);+ if (activeRunId) sendDecision(activeRunId, command.toolId, command.allow, command.remember);return;case 'activateMap':case 'discardMap': {diff --git a/lib/bridge/session-store.ts b/lib/bridge/session-store.tsindex 67db9c5..b87b3b8 100644--- a/lib/bridge/session-store.ts+++ b/lib/bridge/session-store.ts@@ -1,4 +1,5 @@import { browser } from 'wxt/browser';+import type { AgentKind } from '@/lib/agents/catalog';import type { RunItem } from './use-run';import { nameSession } from './socket';@@ -17,7 +18,9 @@ export interface StoredSessionMeta {title?: string;host?: string;url?: string;- claudeSessionId?: string;+ /** The agent CLI that owns `agentSessionId` — another agent cannot resume it. */+ agent?: AgentKind;+ agentSessionId?: string;turns: number;titledAtTurn?: number;namingAt?: number;diff --git a/lib/bridge/side-panel.ts b/lib/bridge/side-panel.tsnew file mode 100644index 0000000..4d0abb0--- /dev/null+++ b/lib/bridge/side-panel.ts@@ -0,0 +1,8 @@+type SidebarAction = { open: () => Promise<void> };++export function openSidePanel(windowId: number) {+ if (import.meta.env.FIREFOX) {+ return (browser as unknown as { sidebarAction: SidebarAction }).sidebarAction.open();+ }+ return browser.sidePanel.open({ windowId });+}diff --git a/lib/bridge/use-run.ts b/lib/bridge/use-run.tsindex d6990c8..b3643d6 100644--- a/lib/bridge/use-run.ts+++ b/lib/bridge/use-run.ts@@ -26,6 +26,7 @@ export type RunItem =summary?: string;ok?: boolean;awaiting?: boolean;+ site?: string;source?: 'local' | 'external';preview?: ScreenshotPreview;};@@ -36,7 +37,7 @@ export interface Run {sessionId: string;send: (text: string) => void;cancel: () => void;- decide: (toolId: string, allow: boolean) => void;+ decide: (toolId: string, allow: boolean, remember?: boolean) => void;clear: () => void;restore: (sessionId: string) => Promise<void>;draft: SiteMapDraft | null;@@ -121,7 +122,8 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {setItems((previous) => attachPreview(previous, runMessage.preview));} else {if (runMessage.event.kind === 'session') {- session.current.claudeSessionId = runMessage.event.claudeSessionId ?? undefined;+ session.current.agent = runMessage.event.agent;+ session.current.agentSessionId = runMessage.event.agentSessionId ?? undefined;}setItems((previous) => reduce(previous, runMessage.event));}@@ -203,7 +205,7 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {setItems((previous) => [...previous, { kind: 'user', id: nextId(), text: trimmed }]);setRunning(true);session.current.turns += 1;- const claudeSessionId = session.current.claudeSessionId;+ const { agent, agentSessionId } = session.current;const failed = () => lost('Lost the connection to the extension — that never went anywhere. Try again.');void browser.tabs.query({ active: true, currentWindow: true })@@ -212,11 +214,13 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {session.current.url = tab.url;session.current.host = hostOf(tab.url) ?? session.current.host;}- const context = tab?.url ? { url: tab.url, tabId: tab.id, claudeSessionId } : { claudeSessionId };+ const context = tab?.url+ ? { url: tab.url, tabId: tab.id, agent, agentSessionId }+ : { agent, agentSessionId };if (!post({ op: 'instruct', text: trimmed, context })) failed();}).catch(() => {- if (!post({ op: 'instruct', text: trimmed, context: { claudeSessionId } })) failed();+ if (!post({ op: 'instruct', text: trimmed, context: { agent, agentSessionId } })) failed();});},[post, lost],@@ -295,9 +299,9 @@ export function useRun({ persist = false }: { persist?: boolean } = {}): Run {if (!post({ op: 'cancel' })) lost('Lost the connection to the extension, so this run is no longer being watched.');}, [post, lost]),decide: useCallback(- (toolId: string, allow: boolean) => {+ (toolId: string, allow: boolean, remember?: boolean) => {setItems((previous) => patchTool(previous, toolId, { awaiting: false }));- post({ op: 'decision', toolId, allow });+ post({ op: 'decision', toolId, allow, remember });},[post],),@@ -375,7 +379,7 @@ function reduce(items: RunItem[], event: RunEvent): RunItem[] {];case 'approval':- return patchTool(items, event.toolId, { awaiting: true });+ return patchTool(items, event.toolId, { awaiting: true, site: event.site });case 'toolResult':return patchTool(items, event.toolId, { ok: event.ok, summary: event.summary, awaiting: false });