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
refactor(bridge): extract useActiveTab so callers can read the tab, not just its URL
Shahriar7081d2cf6905
diff --git a/lib/bridge/use-active-tab-url.ts b/lib/bridge/use-active-tab-url.tsindex f7df245..dca4478 100644--- a/lib/bridge/use-active-tab-url.ts+++ b/lib/bridge/use-active-tab-url.ts@@ -1,35 +1,5 @@-import { useEffect, useState } from 'react';-import { browser } from 'wxt/browser';+import { useActiveTab } from './use-active-tab';export function useActiveTabUrl(): string {- const [url, setUrl] = useState('');-- useEffect(() => {- let live = true;- const refresh = () => {- void browser.tabs- .query({ active: true, currentWindow: true })- .then(([tab]) => {- if (live) setUrl(tab?.url ?? '');- })- .catch(() => {- if (live) setUrl('');- });- };- refresh();-- const onActivated = () => refresh();- const onUpdated = (_id: number, changes: { url?: string }, tab: { active?: boolean }) => {- if (changes.url && tab.active) refresh();- };- browser.tabs.onActivated.addListener(onActivated);- browser.tabs.onUpdated.addListener(onUpdated);- return () => {- live = false;- browser.tabs.onActivated.removeListener(onActivated);- browser.tabs.onUpdated.removeListener(onUpdated);- };- }, []);-- return url;+ return useActiveTab().url;}diff --git a/lib/bridge/use-active-tab.ts b/lib/bridge/use-active-tab.tsnew file mode 100644index 0000000..61d7087--- /dev/null+++ b/lib/bridge/use-active-tab.ts@@ -0,0 +1,49 @@+import { useEffect, useState } from 'react';+import { browser } from 'wxt/browser';++export interface ActiveTab {+ url: string;+ tabId?: number;+ windowId?: number;+ title?: string;+}++const NO_TAB: ActiveTab = { url: '' };++export function useActiveTab(): ActiveTab {+ const [tab, setTab] = useState<ActiveTab>(NO_TAB);++ useEffect(() => {+ let live = true;+ const refresh = () => {+ void browser.tabs+ .query({ active: true, currentWindow: true })+ .then(([found]) => {+ if (!live) return;+ setTab(+ found?.id == null+ ? NO_TAB+ : { url: found.url ?? '', tabId: found.id, windowId: found.windowId, title: found.title },+ );+ })+ .catch(() => {+ if (live) setTab(NO_TAB);+ });+ };+ refresh();++ const onActivated = () => refresh();+ const onUpdated = (_id: number, changes: { url?: string; title?: string }, updated: { active?: boolean }) => {+ if ((changes.url || changes.title) && updated.active) refresh();+ };+ browser.tabs.onActivated.addListener(onActivated);+ browser.tabs.onUpdated.addListener(onUpdated);+ return () => {+ live = false;+ browser.tabs.onActivated.removeListener(onActivated);+ browser.tabs.onUpdated.removeListener(onUpdated);+ };+ }, []);++ return tab;+}