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:
page.ai():
With Output Schema
Return Value
Both methods return aTaskOutput 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
Flight Search
E-commerce Price Comparison
Google Form Submission
Action Cache Output
Everypage.ai() call returns an actionCache that records all actions taken:
Error Handling
Best Practices
Write specific, detailed instructions
Write specific, detailed instructions
Instead of “search for flights”, say “search for round-trip flights from Miami to LAX, departing December 15 and returning December 22, 2025”.
Set appropriate maxSteps
Set appropriate maxSteps
Simple tasks: 10-20 steps. Complex multi-page workflows: 50+ steps. Monitor task outputs and adjust as needed.
Use outputSchema for structured data
Use outputSchema for structured data
When you need specific data extracted, define a Zod schema to get typed, validated output.
Save actionCache for replay
Save actionCache for replay
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