Execute complex multi-step browser tasks with AI-powered automation
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.
import { HyperAgent } from "@hyperbrowser/agent";const agent = new HyperAgent({ llm: { provider: "openai", model: "gpt-4o" },});const page = await agent.newPage();await page.goto("https://flights.google.com");const { output, actionCache } = await page.ai( "Search for round-trip flights from Miami to LAX, leaving Dec 15 and returning Dec 22");console.log(output);// The actionCache can be saved and replayed laterconsole.log(`Completed in ${actionCache.steps.length} steps`);await agent.closeAgent();
executeTask() is a shorthand that creates a page and runs page.ai() for you:
Copy
Ask AI
// This:const result = await agent.executeTask("Go to amazon.com and find the top seller");// Is equivalent to:const page = await agent.newPage();const result = await page.ai("Go to amazon.com and find the top seller");
import { z } from "zod";const result = await agent.executeTask( "Navigate to imdb.com, search for 'The Matrix', and extract the movie details", { outputSchema: z.object({ director: z.string().describe("The name of the movie director"), releaseYear: z.number().describe("The year the movie was released"), rating: z.string().describe("The IMDb rating of the movie"), }), });console.log(result.output);// { director: "Lana Wachowski, Lilly Wachowski", releaseYear: 1999, rating: "8.7/10" }
const page = await agent.newPage();await page.goto("https://flights.google.com");const { output, actionCache } = await page.ai( "Search for round-trip flights from Rio de Janeiro to Los Angeles, " + "leaving December 11, 2025 and returning December 22, 2025. " + "Select the option with the lowest carbon emissions.", { useDomCache: true, enableDomStreaming: true, });// Save actionCache for later replayconsole.log(JSON.stringify(actionCache, null, 2));
const agent = new HyperAgent({ llm: { provider: "openai", model: "gpt-4o" },});const page = await agent.newPage();await page.goto("https://docs.google.com/forms/d/e/1FAIpQLScPkE8wNLpPSkP2d__Ee7xx5Pj7_XDuZ0p16geYWrp73Nutmw/viewform?usp=dialog");// Fill each fieldawait page.perform("fill the name field with John Doe");await page.perform("fill the email field with [email protected]");await page.perform("fill the feedback text area with This is a test submission");await page.perform("select 5 rating option");// Submitawait page.perform("click the submit button");await agent.closeAgent();