Skip to content

armgit / Orkas

Public Imported from GitHub
0

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.

fix(browser): retain submitted addresses while navigation loads

CloudTianTianbbe1a0706cc2
diff --git a/src/main/features/web_assist.ts b/src/main/features/web_assist.ts
index 697aeda4..a54500ea 100644
--- a/src/main/features/web_assist.ts
+++ b/src/main/features/web_assist.ts
@@ -222,6 +222,8 @@ interface WebAssistTabRecord {
suspended?: { url: string; title: string; entries: Array<{ url: string; title: string }>; index: number };
label: string;
loading: boolean;
+ /** Accepted destination until commit; used only by trusted address chrome. */
+ pendingAddressUrl?: string;
errorCode?: WebAssistSnapshot['error_code'];
downloadRequest?: WebAssistTabSnapshot['download_request'];
controlContext?: WebAssistControlContext;
@@ -740,7 +742,9 @@ function rendererSnapshot(record: WebAssistRecord): WebAssistSnapshot {
tabs: state.tabs.map(tab => {
const source = record.tabs.get(tab.tab_id)!;
const contents = source.view?.webContents;
- const rawUrl = contents && !contents.isDestroyed() ? contents.getURL() : source.suspended?.url || '';
+ const rawUrl = source.loading && source.pendingAddressUrl
+ ? source.pendingAddressUrl
+ : contents && !contents.isDestroyed() ? contents.getURL() : source.suspended?.url || '';
return {
...tab,
address_url: rawUrl === 'about:blank' ? rawUrl : safeWebAssistUrl(rawUrl) || '',
@@ -1010,6 +1014,7 @@ function ensureTabLoaded(record: WebAssistRecord, tab: WebAssistTabRecord, load
invalidateObservation(tab);
const view = tab.view;
if (!load) return true;
+ tab.pendingAddressUrl = saved.entries.length ? saved.entries[historyIndex ?? saved.index].url : saved.url;
const loaded = saved.entries.length
? view.webContents.navigationHistory.restore({ entries: saved.entries, index: historyIndex ?? saved.index })
: view.webContents.loadURL(saved.url);
@@ -1389,6 +1394,7 @@ function readWebAssistTextCondition(contents: WebContents, text: string, deadlin
// must never overwrite the current page's state.
function handleLoadFailure(record: WebAssistRecord, tab: WebAssistTabRecord, netCode: number): void {
tab.loading = false;
+ tab.pendingAddressUrl = undefined;
tab.errorCode = 'page_load_failed';
logWebAssistFailure(record.owner.webContents, 'page_load_failed', netCode);
emit(record);
@@ -1568,6 +1574,7 @@ function mountTab(
if (!nativeOptions.webContents) {
const post = details.postBody;
child.loading = true;
+ child.pendingAddressUrl = url;
child.view.webContents.loadURL(url, {
httpReferrer: details.referrer,
...(post ? {
@@ -1617,7 +1624,10 @@ function mountTab(
if (tab.view !== view) return;
if (isMainFrame) {
tab.lastUsedAt = Date.now();
- if (!_isSameDocument) tab.edited = false;
+ if (!_isSameDocument) {
+ tab.edited = false;
+ tab.pendingAddressUrl = safeWebAssistUrl(_url) || undefined;
+ }
invalidateObservation(tab);
}
});
@@ -1630,10 +1640,12 @@ function mountTab(
contents.on('did-stop-loading', () => {
if (tab.view !== view) return;
tab.loading = false;
+ tab.pendingAddressUrl = undefined;
emit(record);
});
contents.on('did-navigate', () => {
if (tab.view !== view) return;
+ tab.pendingAddressUrl = undefined;
// Error documents also emit did-finish-load; only a committed navigation
// proves that a new page has replaced the previous load failure.
if (tab.errorCode === 'page_load_failed') tab.errorCode = undefined;
@@ -1650,6 +1662,7 @@ function mountTab(
});
contents.on('did-navigate-in-page', () => {
if (tab.view !== view) return;
+ tab.pendingAddressUrl = undefined;
invalidateObservation(tab);
emit(record);
});
@@ -1666,6 +1679,7 @@ function mountTab(
contents.on('render-process-gone', (_event, details) => {
if (tab.view !== view) return;
tab.loading = false;
+ tab.pendingAddressUrl = undefined;
tab.errorCode = 'page_load_failed';
if (details?.reason !== 'clean-exit') logWebAssistFailure(record.owner.webContents, 'renderer_gone');
emit(record);
@@ -1798,6 +1812,7 @@ export async function openWebAssist(
tab.assistantAction = undefined;
invalidateObservation(tab);
tab.loading = true;
+ tab.pendingAddressUrl = url;
if (foreground) {
record.activeTabId = tab.id;
for (const candidate of record.tabs.values()) {
@@ -1878,6 +1893,7 @@ export async function navigateWebAssistTo(
tab.assistantAction = undefined;
invalidateObservation(tab);
tab.loading = true;
+ tab.pendingAddressUrl = url;
if (activate) record.activeTabId = tab.id;
emit(record);
tab.view.webContents.loadURL(url).catch(() => undefined);
diff --git a/test/e2e/web_assist_e2e_address.spec.ts b/test/e2e/web_assist_e2e_address.spec.ts
index a84629f8..7a33a1f8 100644
--- a/test/e2e/web_assist_e2e_address.spec.ts
+++ b/test/e2e/web_assist_e2e_address.spec.ts
@@ -1,6 +1,87 @@
import { createServer } from 'node:http';
import { expect, test } from './fixtures/orkas';
+for (const kind of ['URL', 'search'] as const) {
+ test(`browser address stays visible while a ${kind} waits for its first response`, async ({ orkas }) => {
+ const cid = (await orkas.invoke<any>('conversations.create', { title: 'Pending browser address' })).conversation.conversation_id;
+ const page = orkas.page!;
+ let nativeId: number | undefined;
+ try {
+ await page.evaluate(async id => {
+ await (window as any).loadConversations();
+ (window as any).setView('conversation', id);
+ (window as any).ConversationInfo.openAndSetTab('browser');
+ }, cid);
+ await expect(page.locator('.web-assist-tab')).toHaveCount(1);
+ // Hold a real Chromium document response in this isolated browser session.
+ // Search remains deterministic and never contacts the public search service.
+ 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>;
+ let release!: () => void;
+ const pending = new Promise<void>(resolve => { release = resolve; });
+ const gate = { release, requested: '' };
+ (view.webContents as any).__addressResponseGate = gate;
+ view.webContents.session.protocol.handle('https', async request => {
+ gate.requested = request.url;
+ await pending;
+ return new Response('<title>Address ready</title><h1>Navigation completed</h1>', {
+ headers: { 'Content-Type': 'text/html' },
+ });
+ });
+ return view.webContents.id;
+ });
+ const address = page.locator('.web-assist-address-input');
+ const destination = kind === 'URL' ? 'https://address.example.test/slow?item=1#section'
+ : 'https://www.bing.com/search?q=%E4%B8%8A%E6%B5%B7+%E5%A4%A9%E6%B0%94';
+ await address.fill(kind === 'URL' ? destination : '上海 天气');
+ await address.evaluate((node: HTMLInputElement) => {
+ const native = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value')!;
+ (node as any).__addressUpdates = [];
+ Object.defineProperty(node, 'value', {
+ configurable: true,
+ get() { return native.get!.call(this); },
+ set(value) { (this as any).__addressUpdates.push(value); native.set!.call(this, value); },
+ });
+ });
+ await address.press('Enter');
+ await expect.poll(() => orkas.electronApp!.evaluate(({ webContents }, id) =>
+ Boolean((webContents.fromId(id) as any).__addressResponseGate.requested), nativeId!),
+ ).toBe(true);
+ expect(await orkas.electronApp!.evaluate(({ webContents }, id) => webContents.fromId(id)!.getURL(), nativeId)).toBe('');
+ await expect(address).toHaveValue(destination);
+ expect(await address.evaluate((node: HTMLInputElement) => (node as any).__addressUpdates)).not.toContain('');
+ // Blurring or changing tabs must keep the accepted address while loading.
+ await page.locator('.web-assist-add-tab').click();
+ await expect(address).toHaveValue('');
+ await page.locator('.web-assist-tab').first().click();
+ await expect(address).toHaveValue(destination);
+ await address.evaluate((node: HTMLInputElement) => { (node as any).__addressUpdates = []; });
+ const samples = await address.evaluate(async (node: HTMLInputElement) => {
+ const values: string[] = [];
+ for (let frame = 0; frame < 30; frame++) {
+ await new Promise<void>(resolve => requestAnimationFrame(() => resolve()));
+ values.push(node.value);
+ }
+ return values;
+ });
+ expect(samples).toEqual(Array(30).fill(destination));
+ await orkas.electronApp!.evaluate(({ webContents }, id) => (webContents.fromId(id) as any).__addressResponseGate.release(), nativeId);
+ await expect.poll(() => orkas.electronApp!.evaluate(({ webContents }, id) => webContents.fromId(id)!.getTitle(), nativeId!)).toBe('Address ready');
+ await expect(address).toHaveValue(destination);
+ expect(await address.evaluate((node: HTMLInputElement) => (node as any).__addressUpdates)).not.toContain('');
+ } finally {
+ if (nativeId !== undefined) await orkas.electronApp!.evaluate(({ webContents }, id) => {
+ const contents = webContents.fromId(id);
+ if (contents) {
+ (contents as any).__addressResponseGate.release();
+ contents.session.protocol.unhandle('https');
+ }
+ }, nativeId);
+ await orkas.invoke('webAssist.close', {});
+ }
+ });
+}
+
for (const key of ['Enter', 'Space']) {
test(`focused browser close button closes its own tab with ${key}`, async ({ orkas }) => {
const cid = (await orkas.invoke<any>('conversations.create', { title: 'Keyboard browser tabs' })).conversation.conversation_id;
@@ -54,8 +135,11 @@ test('browser address preserves query, fragment and long redirects through editi
}, cid);
const opened = await orkas.invoke<any>('webAssist.open', { conversationId: cid, url: origin + '/start?keep=1#initial' });
expect(opened.ok).toBe(true);
- await expect.poll(async () => (await orkas.invoke<any>('webAssist.state', {})).state.tabs
- .find((tab: any) => tab.tab_id === opened.state.active_tab_id)?.address_url).toBe(origin + '/start?keep=1#initial');
+ await expect.poll(async () => {
+ const tab = (await orkas.invoke<any>('webAssist.state', {})).state.tabs
+ .find((tab: any) => tab.tab_id === opened.state.active_tab_id);
+ return { url: tab?.address_url, loading: tab?.loading };
+ }).toEqual({ url: origin + '/start?keep=1#initial', loading: false });
const nativeId = await orkas.electronApp!.evaluate(({ BrowserWindow, WebContentsView }, url) => {
const view = BrowserWindow.getAllWindows()[0].contentView.children.find(v => v instanceof WebContentsView && v.webContents.getURL() === url) as InstanceType<typeof WebContentsView>;
return view.webContents.id;
@@ -159,7 +243,10 @@ test('empty task browsers keep one blank new tab and preserve existing pages acr
const url = `http://127.0.0.1:${(server.address() as { port: number }).port}/keep?item=1#section`;
await address.fill(url);
await address.press('Enter');
- await expect.poll(async () => (await taskTabs(cid))[0].address_url).toBe(url);
+ await expect.poll(async () => {
+ const tab = (await taskTabs(cid))[0];
+ return { url: tab?.address_url, loading: tab?.loading };
+ }).toEqual({ url, loading: false });
const nativeId = await orkas.electronApp!.evaluate(async ({ BrowserWindow, WebContentsView }, target) => {
const view = BrowserWindow.getAllWindows()[0].contentView.children.find(v => v instanceof WebContentsView && v.webContents.getURL() === target) as InstanceType<typeof WebContentsView>;
await view.webContents.executeJavaScript('document.querySelector("input").value = "Saved draft"');
diff --git a/test/e2e/web_assist_e2e_navigation.spec.ts b/test/e2e/web_assist_e2e_navigation.spec.ts
index 0da2b64f..bc71fec7 100644
--- a/test/e2e/web_assist_e2e_navigation.spec.ts
+++ b/test/e2e/web_assist_e2e_navigation.spec.ts
@@ -22,8 +22,11 @@ test('replacing an in-flight navigation does not show failure, while real failur
}, cid);
const opened = await orkas.invoke<any>('webAssist.open', { conversationId: cid, url: origin + '/ready' });
expect(opened.ok).toBe(true);
- await expect.poll(async () => (await orkas.invoke<any>('webAssist.state', {})).state.tabs
- .find((tab: any) => tab.tab_id === opened.state.active_tab_id)?.address_url).toBe(origin + '/ready');
+ await expect.poll(async () => {
+ const tab = (await orkas.invoke<any>('webAssist.state', {})).state.tabs
+ .find((tab: any) => tab.tab_id === opened.state.active_tab_id);
+ return { url: tab?.address_url, loading: tab?.loading };
+ }).toEqual({ url: origin + '/ready', loading: false });
const nativeId = await orkas.electronApp!.evaluate(({ BrowserWindow, WebContentsView }, url) => {
const view = BrowserWindow.getAllWindows()[0].contentView.children.find(v => v instanceof WebContentsView && v.webContents.getURL() === url) as InstanceType<typeof WebContentsView>;
const page = view.webContents;
diff --git a/test/main/features/web-assist-control.test.ts b/test/main/features/web-assist-control.test.ts
index c9f7f503..d32cae48 100644
--- a/test/main/features/web-assist-control.test.ts
+++ b/test/main/features/web-assist-control.test.ts
@@ -504,6 +504,66 @@ describe('Web Assist controlled connector lifecycle', () => {
vi.restoreAllMocks();
});
+ it.each(['https://example.com/slow?item=1#section', '上海 天气'])(
+ 'publishes the accepted address immediately while %s waits for its first document', async input => {
+ const cid = 'c-pending-address';
+ bindWebAssistConversation('u1', cid, electronMock.renderer);
+ const added = addWebAssistTab('u1', electronMock.renderer, { conversationId: cid });
+ if (!added.ok) throw new Error('Address fixture setup failed');
+ const tabId = added.state.active_tab_id;
+ const page = electronMock.page;
+ const nativeLoad = page.loadURL.bind(page);
+ let finish!: () => Promise<void>;
+ vi.spyOn(page, 'loadURL').mockImplementationOnce((url: string) => new Promise<void>(resolve => {
+ finish = async () => { await nativeLoad(url); resolve(); };
+ }));
+ const destination = input.startsWith('https:') ? input : 'https://www.bing.com/search?q=%E4%B8%8A%E6%B5%B7+%E5%A4%A9%E6%B0%94';
+ electronMock.renderer.send.mockClear();
+ const navigated = await navigateWebAssistTo(electronMock.renderer, { tabId, url: input });
+ expect(page.getURL()).toBe('');
+ expect(navigated).toMatchObject({ ok: true, state: { tabs: [{ loading: true, address_url: destination }] } });
+ const pushed = electronMock.renderer.send.mock.calls.filter(([event]: any[]) => event === 'web-assist:state');
+ expect(pushed.length).toBeGreaterThan(0);
+ for (const [, state] of pushed) expect(state.tabs[0].address_url).toBe(destination);
+ expect(webAssistState(electronMock.renderer).state.tabs[0].address_url).toBe(destination);
+ // Pending chrome state must not claim a document has committed to model consumers.
+ const listed = listModelWebAssistTabs('u1', cid);
+ expect(JSON.stringify(listed)).not.toContain('address_url');
+ expect(listed).toMatchObject({ tabs: [{ display_url: '' }] });
+ await finish();
+ expect(webAssistState(electronMock.renderer).state.tabs[0]).toMatchObject({ loading: false, address_url: destination });
+ },
+ );
+
+ it('replaces pending addresses per tab and resumes the committed address after cancellation or failure', async () => {
+ const cid = 'c-pending-recovery';
+ const opened = await openWebAssist('u1', electronMock.renderer, { conversationId: cid, url: 'https://example.com/ready' });
+ if (!opened.ok) throw new Error('Address recovery fixture setup failed');
+ const tabId = opened.state.active_tab_id;
+ const page = electronMock.page;
+ const nativeLoad = page.loadURL.bind(page);
+ const load = vi.spyOn(page, 'loadURL').mockImplementation(() => new Promise<void>(() => {}));
+ await navigateWebAssistTo(electronMock.renderer, { tabId, url: 'https://example.com/slow' });
+ const replaced = await openWebAssist('u1', electronMock.renderer, { conversationId: cid, tabId, url: 'https://example.com/replacement' });
+ expect(replaced).toMatchObject({ ok: true, state: { tabs: [{ address_url: 'https://example.com/replacement' }] } });
+ const blank = addWebAssistTab('u1', electronMock.renderer, { conversationId: cid });
+ if (!blank.ok) throw new Error('Blank tab fixture setup failed');
+ expect(blank.state.tabs.find(tab => tab.tab_id === blank.state.active_tab_id)?.address_url).toBe('');
+ expect(activateWebAssistTab(electronMock.renderer, tabId)).toMatchObject({ ok: true, state: { tabs: [
+ { address_url: 'https://example.com/replacement' }, { address_url: '' },
+ ] } });
+ page.emit('did-fail-load', {}, -3, 'ERR_ABORTED', 'https://example.com/slow', true);
+ expect(webAssistState(electronMock.renderer).state.tabs[0].address_url).toBe('https://example.com/replacement');
+ page.emit('did-fail-load', {}, -105, 'ERR_NAME_NOT_RESOLVED', 'https://example.com/replacement', true);
+ page.emit('did-stop-loading');
+ expect(webAssistState(electronMock.renderer).state.tabs[0]).toMatchObject({
+ loading: false, error_code: 'page_load_failed', address_url: 'https://example.com/ready',
+ });
+ load.mockRestore();
+ await nativeLoad('https://example.com/recovered');
+ expect(webAssistState(electronMock.renderer).state.tabs[0]).toMatchObject({ loading: false, address_url: 'https://example.com/recovered' });
+ });
+
it('keeps the visible native page mounted when reactivating or reopening the same tab', async () => {
const opened = await openWebAssist('u1', electronMock.renderer, { conversationId: 'c-visible', url: 'https://example.com/ready' });
if (!opened.ok) throw new Error('Visible page fixture setup failed');