Skip to main content
The page.ai() method executes multi-step browser tasks using natural language. It runs an agentic loop that observes the page, makes decisions, and executes actions until the goal is complete.
agent.executeTask() does the same thing—it’s a convenience method that creates a page for you. Use whichever fits your workflow.

Basic Usage

Execute a multi-step task on a specific page:

Parameters

string
required
Natural language description of what you want to accomplish. Be specific for best results.
object
Configuration options for the task execution.
number
default:"50"
Maximum number of actions the AI can take. Increase for complex tasks.
boolean
default:"false"
Reuse DOM snapshots across steps for faster execution.
boolean
default:"false"
Enable screenshots with element overlays for visual understanding.
boolean
default:"false"
Stream DOM updates for more responsive execution.
ZodSchema
Define a Zod schema for structured output extraction at the end of the task.

Example with Options

agent.executeTask()

executeTask() is a shorthand that creates a page and runs page.ai() for you:
It accepts the same parameters as page.ai():

With Output Schema

Return Value

Both methods return a TaskOutput object:

Task Status

Visual Mode

Enable visual mode when the AI needs to understand page layout or when dealing with complex visual elements:
Visual mode uses screenshots which increases token usage and latency. Only enable when visual understanding is necessary.

Real-World Examples

E-commerce Price Comparison

Google Form Submission

Action Cache Output

Every page.ai() call returns an actionCache that records all actions taken:
This cache can be saved and replayed later for deterministic execution without LLM calls.

Error Handling

Best Practices

Instead of “search for flights”, say “search for round-trip flights from Miami to LAX, departing December 15 and returning December 22, 2025”.
Simple tasks: 10-20 steps. Complex multi-page workflows: 50+ steps. Monitor task outputs and adjust as needed.
When you need specific data extracted, define a Zod schema to get typed, validated output.
Store the returned actionCache to replay the same automation later without LLM calls.

Next Steps

page.perform()

Fast single-action execution

page.extract()

Extract structured data

Action Caching

Replay automations without LLM calls

Configuration

Configure LLM providers