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(indicator): mark a working tab on the toolbar badge and its favicon

Shahriar3a70d7137279
diff --git a/entrypoints/content.ts b/entrypoints/content.ts
index 9a419e3..41b87a9 100644
--- a/entrypoints/content.ts
+++ b/entrypoints/content.ts
@@ -1,4 +1,5 @@
import { exposeActions } from '@/lib/actions/host';
+import { exposeIndicator } from '@/lib/indicator/host';
import { exposeMonitor } from '@/lib/monitor/watch';
import { exposeRecorder } from '@/lib/recordings/host';
@@ -11,5 +12,6 @@ export default defineContentScript({
exposeActions();
exposeRecorder();
exposeMonitor();
+ exposeIndicator();
},
});
diff --git a/lib/bridge/run-indicator.ts b/lib/bridge/run-indicator.ts
new file mode 100644
index 0000000..ff091eb
--- /dev/null
+++ b/lib/bridge/run-indicator.ts
@@ -0,0 +1,50 @@
+import { browser } from 'wxt/browser';
+import { INDICATOR_CHANNEL, INDICATOR_COLOR } from '@/lib/indicator/events';
+import { readTabSessions } from './tab-sessions';
+
+type BadgeAction = {
+ setBadgeText: (details: { tabId?: number; text: string }) => Promise<void> | void;
+ setBadgeBackgroundColor: (details: { tabId?: number; color: string }) => Promise<void> | void;
+};
+
+const BUSY_BADGE = '●';
+
+const marked = new Set<number>();
+
+/** Chrome's toolbar key is `action`; Firefox MV2 calls the same surface `browserAction`. */
+function badgeAction(): BadgeAction | null {
+ const api = browser as unknown as { action?: BadgeAction; browserAction?: BadgeAction };
+ return (import.meta.env.FIREFOX ? api.browserAction : api.action) ?? null;
+}
+
+export async function syncRunIndicator(): Promise<void> {
+ const busy = new Set<number>();
+ for (const session of Object.values(await readTabSessions())) {
+ if (session.runId) for (const tabId of session.tabIds) busy.add(tabId);
+ }
+ for (const tabId of busy) if (!marked.has(tabId)) await paint(tabId, true);
+ for (const tabId of [...marked]) if (!busy.has(tabId)) await paint(tabId, false);
+}
+
+export function forgetTab(tabId: number): void {
+ marked.delete(tabId);
+}
+
+async function paint(tabId: number, busy: boolean): Promise<void> {
+ if (busy) marked.add(tabId);
+ else marked.delete(tabId);
+
+ const action = badgeAction();
+ if (action) {
+ try {
+ await action.setBadgeBackgroundColor({ tabId, color: INDICATOR_COLOR });
+ await action.setBadgeText({ tabId, text: busy ? BUSY_BADGE : '' });
+ } catch {
+ marked.delete(tabId);
+ }
+ }
+
+ await browser.tabs
+ .sendMessage(tabId, { channel: INDICATOR_CHANNEL, op: busy ? 'busy' : 'idle' })
+ .catch(() => undefined);
+}
diff --git a/lib/indicator/events.ts b/lib/indicator/events.ts
new file mode 100644
index 0000000..4b629e5
--- /dev/null
+++ b/lib/indicator/events.ts
@@ -0,0 +1,17 @@
+export const INDICATOR_CHANNEL = 'browsentic/indicator';
+
+/** Matches --brand in assets/globals.css; the background has no stylesheet to read it from. */
+export const INDICATOR_COLOR = '#ff7a3d';
+
+export interface IndicatorCommand {
+ channel: typeof INDICATOR_CHANNEL;
+ op: 'busy' | 'idle';
+}
+
+export function isIndicatorCommand(message: unknown): message is IndicatorCommand {
+ return (
+ typeof message === 'object' &&
+ message !== null &&
+ (message as IndicatorCommand).channel === INDICATOR_CHANNEL
+ );
+}
diff --git a/lib/indicator/host.ts b/lib/indicator/host.ts
new file mode 100644
index 0000000..d11e17f
--- /dev/null
+++ b/lib/indicator/host.ts
@@ -0,0 +1,94 @@
+import { browser } from 'wxt/browser';
+import { INDICATOR_COLOR, isIndicatorCommand } from './events';
+
+export { INDICATOR_CHANNEL } from './events';
+
+const ICON_SIZE = 32;
+
+const LINK_ID = 'browsentic-run-icon';
+
+export function exposeIndicator(): void {
+ let original: string | null = null;
+ let marked = false;
+
+ browser.runtime.onMessage.addListener((message: unknown) => {
+ if (!isIndicatorCommand(message)) return;
+ if (message.op === 'busy') void mark();
+ else restore();
+ return Promise.resolve({ ok: true });
+ });
+
+ async function mark(): Promise<void> {
+ if (marked) return;
+ marked = true;
+ const href = currentIconHref();
+ if (original === null) original = href ?? '';
+ const dotted = await withDot(href);
+ if (!dotted || !marked) return;
+ let link = document.getElementById(LINK_ID) as HTMLLinkElement | null;
+ if (!link) {
+ link = document.createElement('link');
+ link.id = LINK_ID;
+ link.rel = 'icon';
+ document.head.append(link);
+ }
+ link.href = dotted;
+ for (const other of iconLinks()) if (other.id !== LINK_ID) other.remove();
+ }
+
+ function restore(): void {
+ if (!marked) return;
+ marked = false;
+ document.getElementById(LINK_ID)?.remove();
+ if (!original) return;
+ const link = document.createElement('link');
+ link.rel = 'icon';
+ link.href = original;
+ document.head.append(link);
+ }
+}
+
+const iconLinks = () => [...document.querySelectorAll<HTMLLinkElement>('link[rel~="icon"]')];
+
+function currentIconHref(): string | null {
+ const link = iconLinks().find((candidate) => candidate.id !== LINK_ID && candidate.href);
+ return link?.href ?? null;
+}
+
+async function withDot(href: string | null): Promise<string | null> {
+ const canvas = document.createElement('canvas');
+ canvas.width = ICON_SIZE;
+ canvas.height = ICON_SIZE;
+ const context = canvas.getContext('2d');
+ if (!context) return null;
+
+ const base = href ? await loadImage(href) : null;
+ if (base) context.drawImage(base, 0, 0, ICON_SIZE, ICON_SIZE);
+
+ const radius = ICON_SIZE * 0.3;
+ const centre = ICON_SIZE - radius - 1;
+ context.beginPath();
+ context.arc(centre, centre, radius + 2, 0, Math.PI * 2);
+ context.fillStyle = 'rgba(0, 0, 0, 0.55)';
+ context.fill();
+ context.beginPath();
+ context.arc(centre, centre, radius, 0, Math.PI * 2);
+ context.fillStyle = INDICATOR_COLOR;
+ context.fill();
+
+ try {
+ return canvas.toDataURL('image/png');
+ } catch {
+ return null;
+ }
+}
+
+function loadImage(href: string): Promise<HTMLImageElement | null> {
+ return new Promise((resolve) => {
+ const image = new Image();
+ image.crossOrigin = 'anonymous';
+ image.onload = () => resolve(image);
+ image.onerror = () => resolve(null);
+ image.src = href;
+ });
+}