Skip to content

Add --wait-until flag to open command and change default to domcontentloaded #479

@go-to-the-future

Description

@go-to-the-future

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): uses command.waitUntil ?? 'load'
  • handleTabNew (src/actions.ts): hardcodes waitUntil: '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 set

Adding a --wait-until flag (accepting load, domcontentloaded, networkidle) would expose this existing capability:

agent-browser open https://example.com --wait-until domcontentloaded

2. Change default from load to domcontentloaded

The Playwright community consensus is that domcontentloaded is the better default for most use cases:

  • load waits for all resources (images, stylesheets, iframes, third-party scripts) — often unnecessary and unreliable
  • domcontentloaded fires when the HTML is parsed and DOM is ready — sufficient for most interactions
  • Agent workflows already follow a navigate → snapshot → interact pattern, so waiting for full load provides 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions