fix: browser tool IPC timeout — add executeJsWithTimeout + isBrowserOpen guard

- browser.ts: add executeJsWithTimeout() wrapping executeJavaScript with 10-15s timeout
  (renderer 冻结时不再无限挂起导致 IPC 25s 超时)
- All browser functions (evaluate/extract/click/type/scroll/screenshot) check isBrowserOpen()
  before execution, return clear error instead of auto-recreating empty browser window
- tool-registry.ts: browser tool IPC timeout increased from 25s to 60s
- Root cause: heavy pages (718+ links) can freeze Chromium renderer, executeJavaScript hangs
  indefinitely; after browser_close, getAgentBrowser() auto-created blank window confusing agent
This commit is contained in:
Metona
2026-04-20 18:10:58 +08:00
parent a8e4f5208c
commit 9999e669d3
2 changed files with 57 additions and 16 deletions
+3 -2
View File
@@ -806,11 +806,12 @@ export async function executeTool(toolName: string, args: Record<string, unknown
};
}
// 其他工具:IPC 调用 + 25 秒硬超时
// 其他工具:IPC 调用 + 硬超时(browser 工具 60 秒,其余 25 秒
const timeoutMs = toolName.startsWith('browser_') ? 60000 : 25000;
const result = await Promise.race([
bridge.tool.execute(toolName, args),
new Promise<ToolResult>((_, reject) =>
setTimeout(() => reject(new Error(`工具 ${toolName} IPC 超时(25秒)`)), 25000)
setTimeout(() => reject(new Error(`工具 ${toolName} IPC 超时(${Math.round(timeoutMs / 1000)}秒)`)), timeoutMs)
)
]);
logToolResult(toolName, result.success, result.success ? undefined : result.error);