[Feature]: Detect "page is waiting for user input" so agents don't poll or wait blindly
Problem / 问题描述
When an agent drives a web app through ego-browser, it cannot promptly tell that the page has transitioned into a state that requires a user/agent decision. In our scenario the driving agent was operating an internal AI-chat SPA: mid-conversation, the in-page assistant rendered an interactive card ("waiting for your input": radio options + a submit button). The driver's wait loop kept sleeping/polling for its own completion marker, treating the question card as "not finished yet". Nothing surfaced "action required" — a human watching the browser had to interrupt and tell the agent "the page is waiting for you to pick an option". Without that human, the agent would have waited indefinitely.
用 ego-browser 驱动 Web 应用时,如果页面中途进入“需要用户操作/决策”的状态(例如页面内的 AI 助手弹出一张交互卡片:单选组 + 提交按钮,等待选择),驱动方 Agent 基本无法及时感知。它只能按自己的完成标记做间隔轮询或干等,会把“等待输入”误判为“任务还在进行”。本次实际场景就是旁边的人观察到页面在等待选择、手动打断后,Agent 才去操作——否则会一直等下去。
Why current primitives don't cover it / 现有能力为什么覆盖不了
waitForSelector/waitForFunction/waitForLoadState都是应用特定的:驱动方必须事先知道“待输入状态”的确切 selector/条件。对 agent-in-agent(页面里的人/AI 动态生成提问 UI)的场景,提问 UI 是运行时生成的,事先无法枚举。page.events()是拉取式的协议事件缓冲(需要主动 drain),不是阻塞订阅——它无法“唤醒”正在等待的驱动方,协议事件也不携带“这里需要人/驱动 Agent 做个决定”的语义。- 没有“actionable / awaiting-input”这类页面状态的概念,于是每个驱动方都自己写轮询循环:浪费轮次与 token,且只要触发 UI 不在预注册条件内就会一直 stall。
Minimal sketch / 现状与期望的最小示意
// TODAY — blind polling; a question card does not match the completion marker
sendMessage("dev task ...");
while (true) {
await new Promise(r => setTimeout(r, 15000));
const text = await page.evaluate(() => document.body.innerText);
if (text.includes("done")) break; // never fires while the page waits for input
}
// DESIRED — a blocking, semantic wait that returns actionable candidates
const r = await page.waitForInteractionRequired({ timeoutMs: 600000 });
// r => { required: true, candidates: [{ ref: "@275", kind: "radio+submit", label: "..." }] }Suggested directions / 建议方向(供参考,欢迎任何形式的改进)
- Blocking semantic wait, e.g.
await page.waitForInteractionRequired()(a.k.a.waitForUserAction()/waitForAttention()), returning candidate node refs. Heuristic signals could include: a newly appeared subtree containing enabled form controls (radio/select/input) and a visible enabled submit button; focus moving into such a subtree;role=alertdialog/aria-liveannouncements; or an explicit page-provided flag where apps can declare "input required". - Mutation-based "actionable change since last look" API, e.g.
waitForActionableChange({ since }), so drivers don't need app-specific selectors at all. - Subscribable channel (
page.on(...)-style or blockingwaitForEvent) that pushes actionable-state transitions, complementing today's bufferedevents(). - If this is out of core scope, document a canonical pattern in SKILL.md: while waiting on long-running page work, take a cheap semantic probe (e.g. compact
snapshotTextof the main content region) each interval, and treat "newly appeared enabled interactive controls / question-like cards" as a mandatory stop-and-look trigger — at minimum making today's blind-wait failure mode explicit.
Impact / 影响
- Agent-in-agent (an in-page AI asks the driving agent to choose) workflows stall until a human intervenes; we hit this in real usage.
- Polling loops waste tokens/time and miss UI transitions that don't match pre-registered selectors.
- Even a documented pattern + a simple heuristic wait primitive would materially reduce babysitting.
Environment / 环境
- ego-browser 0.5.0.32 (chromium 152.0.7977.54), Node v24.18.1, macOS (arm64).
- Driving style: scripts via the
ego-browser nodejsharness, one TaskSpace reused across rounds.
Source: citrolabs/ego-lite