Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(browser): older extensions wait for a loadState by polling the tab, not by navigating

Dash5b5a7c2e721b
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
index 37ce629b4e..e374645408 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/user-browser-backend.test.ts
@@ -328,6 +328,13 @@ describe('UserBrowserBackend · 读取与动作', () => {
expect(
await call(b, { action: 'act', targetId: 't1', request: { kind: 'wait', timeMs: 1 } }),
).toMatchObject({ ok: true, data: { kind: 'wait', waitedMs: 1 } });
+ // Review 2026-10-30 (Codex P2): a loadState wait on an older extension must not navigate the tab.
+ fake.responses.set('tabs', () => ({ ok: true, tabs: [{ id: 7, url: 'https://example.test/a', status: 'complete' }] }));
+ const navigatesBefore = fake.jobs.filter(([name]) => name === 'navigate').length;
+ expect(
+ await call(b, { action: 'act', targetId: 't1', request: { kind: 'wait', loadState: 'load' } }),
+ ).toMatchObject({ ok: true, data: { kind: 'wait', loadState: 'load' } });
+ expect(fake.jobs.filter(([name]) => name === 'navigate').length).toBe(navigatesBefore);
for (const request of [
{ kind: 'click', ref: 'r1', doubleClick: true },
{ kind: 'drag', startRef: 'a', endRef: 'b' },
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
index 680ba9cd1d..1446b9aeab 100644
--- a/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/user-browser-backend.ts
@@ -1407,15 +1407,31 @@ export class UserBrowserBackend implements BrowserBackend {
});
}
if (request.loadState) {
- const job = await bridge.act('navigate', { url: record.url, browser: record.clientId });
- if (!job.ok) return this.failureResult(req.action, job);
- return actionOk(req.action, {
- backend: this.kind,
- targetId: record.targetId,
- kind: 'wait',
- loadState: request.loadState,
- url: job.url ?? record.url,
- });
+ // Older extensions cannot wait inside the page: poll the tab's own load state. (Navigating to
+ // the recorded address here would reload a page that was just submitted.)
+ const deadline = started + timeoutMs;
+ for (;;) {
+ const listed = await bridge.act('tabs', { browser: record.clientId, limit: 100 });
+ const current =
+ listed.ok && Array.isArray(listed.tabs)
+ ? (listed.tabs as Array<{ id?: unknown; url?: unknown; status?: unknown }>).find(
+ (t) => t.id === record.tabId,
+ )
+ : undefined;
+ if (current?.status === 'complete') {
+ if (typeof current.url === 'string') record.url = current.url;
+ return actionOk(req.action, {
+ backend: this.kind,
+ targetId: record.targetId,
+ kind: 'wait',
+ loadState: request.loadState,
+ url: record.url,
+ });
+ }
+ if ((this.opts.now ?? Date.now)() >= deadline)
+ return actionFailed(req.action, `等待 ${timeoutMs}ms 后页面仍未加载完成`);
+ await sleep(250);
+ }
}
if (request.url) {
const deadline = started + timeoutMs;