-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
Problem
The open command currently uses waitUntil: 'load' by default when navigating. This frequently causes timeouts on modern SPAs that rely on external scripts (analytics, auth providers, etc.) which delay the load event indefinitely.
This is especially problematic for AI agent workflows where the agent navigates to a URL and expects to interact with the page promptly. A timeout here wastes an entire agent turn and can cascade into repeated failures.
Observation: Internal Inconsistency
The daemon already has an inconsistency in waitUntil defaults:
handleNavigate(src/actions.ts): usescommand.waitUntil ?? 'load'handleTabNew(src/actions.ts): hardcodeswaitUntil: 'domcontentloaded'
// handleNavigate - defaults to 'load'
await page.goto(command.url, { waitUntil: command.waitUntil ?? 'load' });
// handleTabNew - uses 'domcontentloaded'
await page.goto(command.url, { waitUntil: 'domcontentloaded' });The tab new command already chose the more practical default.
Proposal
1. Add --wait-until CLI flag to open command
The daemon already supports the waitUntil field on NavigateCommand (src/types.ts), but the Rust CLI (cli/src/commands.rs) never passes it through:
// Current (line 102)
let mut nav_cmd = json\!({ "id": id, "action": "navigate", "url": url });
// waitUntil is never setAdding a --wait-until flag (accepting load, domcontentloaded, networkidle) would expose this existing capability:
agent-browser open https://example.com --wait-until domcontentloaded2. Change default from load to domcontentloaded
The Playwright community consensus is that domcontentloaded is the better default for most use cases:
loadwaits for all resources (images, stylesheets, iframes, third-party scripts) — often unnecessary and unreliabledomcontentloadedfires when the HTML is parsed and DOM is ready — sufficient for most interactions- Agent workflows already follow a
navigate → snapshot → interactpattern, so waiting for fullloadprovides no additional value
This would also align handleNavigate with handleTabNew.
Changes Required
| File | Change |
|---|---|
cli/src/flags.rs |
Add wait_until: Option<String> field + --wait-until parsing |
cli/src/commands.rs |
Pass flags.wait_until as waitUntil in navigate JSON command |
src/actions.ts |
Change default: command.waitUntil ?? 'load' → command.waitUntil ?? 'domcontentloaded' |
Happy to submit a PR if this direction sounds good.