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(android): fixes from the end-to-end pass: switching Android off and on again no longer reuses the old connection's DevTools sessions, the phone tab shows Agent working during a run, and the Firefox build leaves the phone pages out
Shahriarc17cea401cf6
diff --git a/docs/guide/features/android.md b/docs/guide/features/android.mdindex 518e892..7a64e19 100644--- a/docs/guide/features/android.md+++ b/docs/guide/features/android.md@@ -55,6 +55,8 @@ front on the phone, kept up to date as it changes.has focus to type on the phone. The bar above has back, forward, reload, the page's address (typean address or a search to go there) and the phone's tabs.- **It follows the phone.** Switch tabs on the phone itself and the picture follows.+- **You can see when the agent is at work.** **Agent working** shows at the top of the phone frame+ while a run is going. The phone stays yours to use meanwhile.- **Switch it off**, or close the phone tab, to stop. Unplugging the phone or closing Chrome on itends the session too, and the phone tab says why, with a button to reconnect.diff --git a/docs/internals/extension.md b/docs/internals/extension.mdindex b5269f5..0710684 100644--- a/docs/internals/extension.md+++ b/docs/internals/extension.md@@ -434,7 +434,8 @@ Driving a phone (see [Android phones](android.md)) adds two unlisted entrypointsThe phone session itself is `browsentic/phone` in `storage.session`, written only through`phone.ts`, and the side panel and popup read it with `usePhoneSession`. The panel recognises thephone tab by its id, not its URL: without the `tabs` permission an extension page's URL is hidden-from `tabs.query`. The **Android** toggle is hidden on Firefox, and no new permission was needed.+from `tabs.query`. The **Android** toggle is hidden on Firefox, and the Firefox build leaves out both entrypoints. No new+permission was needed.## Tab scopingdiff --git a/src/extension/entrypoints/phone-page.ts b/src/extension/entrypoints/phone-page.tsindex 9e7e007..21b59bb 100644--- a/src/extension/entrypoints/phone-page.ts+++ b/src/extension/entrypoints/phone-page.ts@@ -1,3 +1,3 @@import { installPhoneApi } from '@/lib/phone/page-api';-export default defineUnlistedScript(() => installPhoneApi());+export default defineUnlistedScript({ exclude: ['firefox'], main: () => installPhoneApi() });diff --git a/src/extension/entrypoints/phone/App.tsx b/src/extension/entrypoints/phone/App.tsxindex 4f26fae..c07bbcb 100644--- a/src/extension/entrypoints/phone/App.tsx+++ b/src/extension/entrypoints/phone/App.tsx@@ -6,6 +6,7 @@ import { ANDROID_PROTOCOL } from '@/lib/actions/protocol';import { askPhone, usePhoneSession } from '@/lib/bridge/phone-client';import type { PhoneEndReason, PhoneSession } from '@/lib/bridge/phone';import { useDaemonState } from '@/lib/bridge/use-daemon-state';+import { useTabSessions } from '@/lib/bridge/use-tab-sessions';import { addressOf } from '@/lib/phone/mirror';import { cn } from '@/lib/utils';import { useMirror, type Mirror } from './use-mirror';@@ -59,6 +60,7 @@ export default function App() {const visible = useVisible();const live = !!session && !session.ended && !session.waitingForChrome;const mirror = useMirror(live && visible);+ const working = useTabSessions().some((each) => each.runId !== null && each.phone?.serial === session?.serial);const device = daemon?.android?.devices.find((each) => each.serial === session?.serial);const asleep = device?.problem?.code === 'SCREEN_OFF';const tooOld = !!daemon?.connected && (daemon.protocolVersion ?? 0) < ANDROID_PROTOCOL;@@ -91,8 +93,8 @@ export default function App() {return (<div className="dot-grid flex h-screen flex-col items-center gap-3 overflow-hidden p-4"><Header session={session} />- <PhoneFrame session={session} device={device} mirror={mirror} live={live} overlay={overlay} />- {mirror.error && <p className="rounded-lg border border-destructive/40 bg-surface px-3 py-1.5 text-xs text-ink">{mirror.error}</p>}+ <PhoneFrame session={session} device={device} mirror={mirror} live={live} working={live && working} overlay={overlay} />+ {live && mirror.error && <p className="rounded-lg border border-destructive/40 bg-surface px-3 py-1.5 text-xs text-ink">{mirror.error}</p>}</div>);}@@ -122,12 +124,15 @@ function PhoneFrame({device,mirror,live,+ working,overlay,}: {session: PhoneSession | null;device?: { transport: 'usb' | 'wifi'; screen?: { width: number; height: number } };mirror: Mirror;live: boolean;+ /** A conversation on this phone has a run going; the user can still use the phone meanwhile. */+ working: boolean;overlay: ReactNode;}) {const [tabsOpen, setTabsOpen] = useState(false);@@ -138,6 +143,12 @@ function PhoneFrame({<div className="flex flex-col rounded-[2.25rem] border border-line-strong bg-surface p-2.5 shadow-2xl" style={{ width: screen.width + FRAME_CHROME_PX.width }}><div className="flex items-center justify-between px-3 pt-1 pb-2 text-[11px] text-ink-dim"><span className="truncate font-medium text-ink">{session?.model ?? 'Android'}</span>+ {working && (+ <span role="status" className="flex shrink-0 items-center gap-1.5 rounded-full bg-brand/12 px-2 py-0.5 text-brand">+ <span className="size-1.5 animate-pulse rounded-full bg-brand" />+ Agent working+ </span>+ )}<span className="flex items-center gap-1.5"><span className={cn('glow-dot size-1.5 rounded-full', live ? 'bg-lime' : 'bg-amber')} />{device?.transport === 'wifi' ? 'Wi-Fi' : 'USB'}diff --git a/src/extension/entrypoints/phone/index.html b/src/extension/entrypoints/phone/index.htmlindex f96f013..2751465 100644--- a/src/extension/entrypoints/phone/index.html+++ b/src/extension/entrypoints/phone/index.html@@ -4,6 +4,7 @@<meta charset="UTF-8" /><meta name="color-scheme" content="dark" /><meta name="viewport" content="width=device-width, initial-scale=1.0" />+ <meta name="manifest.exclude" content="['firefox']" /><title>Android · Browsentic</title></head><body>diff --git a/src/lib/bridge/phone-mirror.test.ts b/src/lib/bridge/phone-mirror.test.tsindex 7a9fe4e..2810f74 100644--- a/src/lib/bridge/phone-mirror.test.ts+++ b/src/lib/bridge/phone-mirror.test.ts@@ -75,6 +75,16 @@ beforeEach(async () => {});describe('the mirror in the background', () => {+ test('a session the extension ended attaches afresh next time, since a new connection knows none of the old sessions', async () => {+ const { attachedSession } = await import('./phone-mirror');+ const { endPhone } = await import('./phone');+ await attachedSession(SERIAL, FRONT);+ await attachedSession(SERIAL, FRONT);+ await endPhone('closed');+ await attachedSession(SERIAL, FRONT);+ expect(methods().filter((method) => method === 'Target.attachToTarget')).toHaveLength(2);+ });+test('watching follows the tab in front, not the first listed, and streams it', async () => {const page = connectPage();page.say({ op: 'watch' });diff --git a/src/lib/bridge/phone-mirror.ts b/src/lib/bridge/phone-mirror.tsindex f0f31f0..44b573e 100644--- a/src/lib/bridge/phone-mirror.ts+++ b/src/lib/bridge/phone-mirror.ts@@ -1,7 +1,7 @@import { browser, type Browser } from 'wxt/browser';import { PHONE_PORT, keyEvents, type MirrorCommand, type MirrorMessage, type PageState } from '@/lib/phone/mirror';import type { PhoneTarget } from '@/lib/phone/types';-import { numbered, readPhone, updatePhone, type PhoneSession } from './phone';+import { numbered, onPhoneReset, readPhone, updatePhone, type PhoneSession } from './phone';import { refusalFor } from './site-guard';import { onCdpEvent, onDaemonClosed, onPhoneClosed, sendCdp, type CdpEvent } from './socket';import { hostOf, patchSession, sessionForTab } from './tab-sessions';@@ -349,4 +349,5 @@ export function servePhoneMirror(): void {onCdpEvent(onEvent);onPhoneClosed(forget);onDaemonClosed(forget);+ onPhoneReset(forget);}diff --git a/src/lib/bridge/phone.ts b/src/lib/bridge/phone.tsindex 52c924c..1afd3c5 100644--- a/src/lib/bridge/phone.ts+++ b/src/lib/bridge/phone.ts@@ -60,6 +60,15 @@ export async function readPhone(): Promise<PhoneSession | null> {return (stored[PHONE_KEY] as PhoneSession | undefined) ?? null;}+const resetListeners = new Set<() => void>();++/** Hears the extension end or replace the session itself, which the Bridge never reports back: a new DevTools connection knows none of the old one's sessions. */+export const onPhoneReset = (listener: () => void): void => void resetListeners.add(listener);++function reset(): void {+ for (const listener of resetListeners) listener();+}+const writePhone = (session: PhoneSession | null): Promise<void> =>session ? browser.storage.session.set({ [PHONE_KEY]: session }) : browser.storage.session.remove(PHONE_KEY);@@ -96,6 +105,7 @@ export function startPhone(serial: string, windowId?: number): Promise<ActionResreturn success(held);}if (held && !held.ended) closePhone(held.serial);+ reset();const opened = await openPhone(serial);if (!opened.ok && opened.error.code !== 'CHROME_NOT_RUNNING') return opened;@@ -127,6 +137,7 @@ export function endPhone(reason: PhoneEndReason): Promise<void> {if (!held) return;if (reason === 'closed') {if (!held.ended) closePhone(held.serial);+ reset();await writePhone(null);await clearNotification();if (await tabExists(held.mirrorTabId)) await browser.tabs.remove(held.mirrorTabId).catch(() => undefined);