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
fix(extension): page.navigate leaves a tab that is not a web page through the tabs API without messaging the page first, since an extension page in a tab answers tabs.sendMessage and its empty answer read as a navigation that happened
Shahriar833684b33aea
diff --git a/src/lib/bridge/invoke.test.ts b/src/lib/bridge/invoke.test.tsnew file mode 100644index 0000000..e2d09cd--- /dev/null+++ b/src/lib/bridge/invoke.test.ts@@ -0,0 +1,61 @@+import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest';+import { fakeBrowser } from 'wxt/testing';+import { success } from '@/lib/actions/protocol';+import { BLOCKED_SITES_KEY, SITE_BLOCKED } from '@/lib/settings/blocked-sites';+import { invokeForHarness } from './invoke';++const HOME = 'chrome-extension://abcdef/newtab.html';++const tabOn = async (url?: string) => (await fakeBrowser.tabs.create({ url, active: true })).id!;++let sent: ReturnType<typeof vi.fn>;++beforeEach(() => {+ fakeBrowser.reset();+ sent = vi.fn(async () => success({}));+ vi.spyOn(fakeBrowser.tabs, 'sendMessage').mockImplementation(sent as never);+ const update = fakeBrowser.tabs.update.bind(fakeBrowser.tabs);+ vi.spyOn(fakeBrowser.tabs, 'update').mockImplementation((async (tabId: number, info: { url?: string }) => {+ const tab = await update(tabId, info);+ setTimeout(() => void fakeBrowser.tabs.onUpdated.trigger(tabId, { status: 'complete' }, tab), 0);+ return tab;+ }) as never);+});++afterEach(() => vi.restoreAllMocks());++describe('navigating away from a page that is not a web page', () => {+ test('the browser moves the tab, and nothing is sent into the page', async () => {+ const tabId = await tabOn(HOME);+ expect(await invokeForHarness('page.navigate', { url: 'https://example.com/' }, tabId)).toMatchObject({+ ok: true,+ data: { navigatedTo: 'https://example.com/', loaded: true },+ });+ expect((await fakeBrowser.tabs.get(tabId)).url).toBe('https://example.com/');+ expect(sent).not.toHaveBeenCalled();+ });++ test('a tab whose address the browser keeps from the extension is moved the same way', async () => {+ const tabId = await tabOn();+ expect(await invokeForHarness('page.navigate', { url: 'https://example.com/' }, tabId)).toMatchObject({ ok: true });+ expect(sent).not.toHaveBeenCalled();+ });++ test('a blocked destination is still refused, and the tab stays put', async () => {+ await fakeBrowser.storage.local.set({ [BLOCKED_SITES_KEY]: ['mybank.com'] });+ const tabId = await tabOn(HOME);+ expect(await invokeForHarness('page.navigate', { url: 'https://mybank.com/' }, tabId)).toMatchObject({+ ok: false,+ error: { code: SITE_BLOCKED },+ });+ expect((await fakeBrowser.tabs.get(tabId)).url).toBe(HOME);+ });++ test('a relative address has nothing to resolve against, and the error says to pass a full one', async () => {+ const tabId = await tabOn(HOME);+ expect(await invokeForHarness('page.navigate', { url: '/docs' }, tabId)).toMatchObject({+ ok: false,+ error: { code: 'INVALID_INPUT', message: expect.stringContaining('absolute http(s) URL') },+ });+ });+});diff --git a/src/lib/bridge/invoke.ts b/src/lib/bridge/invoke.tsindex 5fa33da..88a83b3 100644--- a/src/lib/bridge/invoke.ts+++ b/src/lib/bridge/invoke.ts@@ -253,7 +253,7 @@ async function routeInTab(runId: string | undefined,owner: TabSession | null,): Promise<ActionResult> {- if (action === navigate.name) return navigateTab(tab.id, input);+ if (action === navigate.name) return isWebPage(tab.url) ? navigateTab(tab.id, input) : navigateViaTabsApi(tab.id, input);if (action === searchSite.name) return searchTab(tab.id, input);if (action === switchTab.name) return switchSessionTab({ id: tab.id, windowId: tab.windowId }, input, owner);if (action === switchFrame.name) return switchFrameInTab(tab.id, tab.url, input);