Orkas is an open-source (MIT), local-first AI team for your desktop: a Commander turns your goal into to-dos and coordinates 16 built-in specialist agents plus Claude Code, Codex, OpenCode, OpenClaw and Hermes, with projects, scheduled automations and connectors. Free app for macOS & Windows; built-in models or your own keys.
JavaScript agent-collaborationagent-harnessagent-orchestrationagent-teamagent-workflowai-assistantai-automationai-employeeai-productivityai-teamai-workflowautonomous-agentsclaude-code-guiclaude-coworkdesktop-agentlocal-firstmulti-agentmulti-agent-systemself-evolving-agentstask-automation
Recover local browser navigation after service startup
wyt9b7f3b9e8950
diff --git a/src/main/features/web_assist.ts b/src/main/features/web_assist.tsindex c84a06fd..2bf0441a 100644--- a/src/main/features/web_assist.ts+++ b/src/main/features/web_assist.ts@@ -269,7 +269,10 @@ function directWebAssistAddress(value: string): string | null {const normalized = safeWebAssistUrl(`https://${value}`);if (!normalized) return null;const hostname = new URL(normalized).hostname.replace(/^\[|\]$/gu, '').toLowerCase();- if (hostname === 'localhost') return normalized;+ if (hostname === 'localhost' || hostname === '::1' || /^127(?:\.\d{1,3}){3}$/u.test(hostname)) {+ // Reparse the input so an explicit :443 survives HTTPS default-port normalization.+ return safeWebAssistUrl(`http://${value}`);+ }if (hostname.includes(':')) return normalized;if (/^\d{1,3}(?:\.\d{1,3}){3}$/u.test(hostname)) return normalized;return hostname.includes('.') ? normalized : null;diff --git a/test/e2e/web_assist_e2e_address.spec.ts b/test/e2e/web_assist_e2e_address.spec.tsindex 91e1a5ce..e23b4ab6 100644--- a/test/e2e/web_assist_e2e_address.spec.ts+++ b/test/e2e/web_assist_e2e_address.spec.ts@@ -10,6 +10,74 @@ const test = base.extend({},});+test('a scheme-less loopback address recovers after its local service becomes ready', async ({ orkas }) => {+ let pageRequests = 0;+ const server = createServer((req, res) => {+ if (req.url === '/ready?item=one') pageRequests++;+ res.setHeader('Content-Type', 'text/html');+ res.setHeader('Cache-Control', 'no-store');+ res.end('<title>Local service ready</title><h1>Local service ready</h1>');+ });+ await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));+ const port = (server.address() as { port: number }).port;+ await new Promise<void>(resolve => server.close(() => resolve()));+ const page = orkas.page!;+ const cid = (await orkas.invoke<any>('conversations.create', { title: 'Local service startup' })).conversation.conversation_id;+ try {+ await page.evaluate(async id => {+ const app = window as any;+ await app.loadConversations(); app.setView('conversation', id);+ app.ConversationInfo.openAndSetTab('browser');+ }, cid);+ await expect(page.locator('.web-assist-tab')).toHaveCount(1);+ const tabId = (await orkas.invoke<any>('webAssist.state')).state.active_tab_id;+ const nativeId = await orkas.electronApp!.evaluate(({ BrowserWindow, WebContentsView }) => {+ const view = BrowserWindow.getAllWindows()[0].contentView.children.find(v => v instanceof WebContentsView && v.webContents.getURL() === '') as InstanceType<typeof WebContentsView>;+ (globalThis as any).__loopbackNetErrors = [];+ view.webContents.on('did-fail-load', (_event, code) => (globalThis as any).__loopbackNetErrors.push(code));+ return view.webContents.id;+ });+ const address = page.locator('.web-assist-address-input');+ const input = `127.0.0.1:${port}/ready?item=one#board`;+ await address.fill(input); await address.press('Enter');+ await expect.poll(async () => (await orkas.invoke<any>('webAssist.state')).state.error_code).toBe('page_load_failed');+ expect(await orkas.electronApp!.evaluate(() => (globalThis as any).__loopbackNetErrors)).toContain(-102);+ const root = require('node:path').resolve(__dirname, '../..');+ await orkas.electronApp!.evaluate(({ BrowserWindow }, args) => {+ const require = (process as any).mainModule.require;+ require(args.root + '/src/main/features/web_assist.ts').bindWebAssistConversation('account-e2e', args.cid, BrowserWindow.getAllWindows()[0].webContents);+ require(args.root + '/src/main/features/web_assist_lifecycle.ts').beginBrowserTaskRun('account-e2e', args.cid, 'loopback-startup');+ (globalThis as any).__loopbackWaitTool = require(args.root + '/src/main/features/group_chat/browser_tool.ts').buildConversationBrowserTool('account-e2e', args.cid);+ }, { root, cid });+ const wait = () => orkas.electronApp!.evaluate(async (_electron, tabId) => {+ const result = await (globalThis as any).__loopbackWaitTool.execute({ operation: 'wait', tab_id: tabId, wait_condition: 'loaded', timeout_ms: 500 }, { state: {} });+ return { ...JSON.parse(result.content), isError: result.isError === true };+ }, tabId);+ expect(await wait()).toMatchObject({ ok: false, code: 'page_load_failed', isError: true });+ await new Promise<void>(resolve => server.listen(port, '127.0.0.1', resolve));+ // Service readiness alone must not turn an un-retried error document into success.+ expect(await wait()).toMatchObject({ ok: false, code: 'page_load_failed', isError: true });+ expect(pageRequests).toBe(0);+ await address.fill(input); await address.press('Enter');+ await expect.poll(async () => {+ const state = (await orkas.invoke<any>('webAssist.state')).state;+ return { url: state.tabs.find((tab: any) => tab.tab_id === tabId)?.address_url, loading: state.loading, error: state.error_code || null };+ }).toEqual({ url: `http://${input}`, loading: false, error: null });+ expect(await wait()).toMatchObject({ ok: true, isError: false });+ expect(await orkas.electronApp!.evaluate(async ({ webContents }, id) => webContents.fromId(id)!.executeJavaScript('document.querySelector("h1")?.textContent'), nativeId)).toBe('Local service ready');+ expect(pageRequests).toBe(1);+ await orkas.electronApp!.evaluate((_electron, args) => {+ const require = (process as any).mainModule.require;+ require(args.root + '/src/main/features/web_assist_lifecycle.ts').finishBrowserTaskRun('account-e2e', args.cid, 'loopback-startup');+ delete (globalThis as any).__loopbackWaitTool;+ }, { root, cid });+ } finally {+ await orkas.invoke('webAssist.close', {});+ server.closeAllConnections();+ if (server.listening) await new Promise<void>(resolve => server.close(() => resolve()));+ }+});+test('scrolled browser tabs stay in place through page updates, activation and tab changes', async ({ orkas }) => {const server = createServer((_req, res) => {res.setHeader('Content-Type', 'text/html');diff --git a/test/main/features/web_assist.test.ts b/test/main/features/web_assist.test.tsindex e18a8083..12bff7ce 100644--- a/test/main/features/web_assist.test.ts+++ b/test/main/features/web_assist.test.ts@@ -141,8 +141,8 @@ describe('Web Assist security boundary', () => {it('opens address-bar URLs and domains directly, then searches ordinary text with Bing', () => {expect(normalizeWebAssistUserUrl('example.com/docs')).toBe('https://example.com/docs');expect(normalizeWebAssistUserUrl('http://localhost:4400')).toBe('http://localhost:4400/');- expect(normalizeWebAssistUserUrl('localhost:4400/docs')).toBe('https://localhost:4400/docs');- expect(normalizeWebAssistUserUrl('127.0.0.1:4400/docs')).toBe('https://127.0.0.1:4400/docs');+ expect(normalizeWebAssistUserUrl('localhost:4400/docs')).toBe('http://localhost:4400/docs');+ expect(normalizeWebAssistUserUrl('127.0.0.1:4400/docs')).toBe('http://127.0.0.1:4400/docs');for (const query of ['orkas', '上海 天气']) {const result = normalizeWebAssistUserUrl(query);@@ -158,6 +158,33 @@ describe('Web Assist security boundary', () => {}});+ it.each([+ ['localhost', 'http://localhost/'],+ ['localhost:4400/docs?item=one#board', 'http://localhost:4400/docs?item=one#board'],+ ['LOCALHOST:443/one%20two?x=%2F&x=two#hash', 'http://localhost:443/one%20two?x=%2F&x=two#hash'],+ ['127.0.0.1:443/ready', 'http://127.0.0.1:443/ready'],+ ['127.0.0.2:8080/', 'http://127.0.0.2:8080/'],+ ['127.1:4400/docs', 'http://127.0.0.1:4400/docs'],+ ['[::1]:4400/docs', 'http://[::1]:4400/docs'],+ ['[0:0:0:0:0:0:0:1]:443/ready', 'http://[::1]:443/ready'],+ ])('opens a scheme-less loopback address over HTTP: %s', (input, expected) => {+ expect(normalizeWebAssistUserUrl(input)).toBe(expected);+ });++ it.each([+ ['localhost.example.test:4400/docs', 'https://localhost.example.test:4400/docs'],+ ['127.0.0.1.example.test:4400/docs', 'https://127.0.0.1.example.test:4400/docs'],+ ['192.168.1.1:4400/docs', 'https://192.168.1.1:4400/docs'],+ ['[2001:db8::1]:4400/docs', 'https://[2001:db8::1]:4400/docs'],+ ['example.com:80/docs', 'https://example.com:80/docs'],+ ['http://localhost:443/docs', 'http://localhost:443/docs'],+ ['https://localhost:4400/docs', 'https://localhost:4400/docs'],+ ['http://[::1]:443/docs', 'http://[::1]:443/docs'],+ ['https://127.0.0.1:4400/docs', 'https://127.0.0.1:4400/docs'],+ ])('preserves explicit protocols and non-loopback address defaults: %s', (input, expected) => {+ expect(normalizeWebAssistUserUrl(input)).toBe(expected);+ });+it('clamps renderer geometry to the owner window and rejects unusable rectangles', () => {expect(normalizeWebAssistBounds({ x: -10.2, y: 12.9, width: 2_000, height: 2_000 },