Skip to main content
HyperAgent supports managing multiple browser pages within a single agent instance. This is useful for workflows that require data from multiple sources or parallel processing.

Creating Multiple Pages

import { HyperAgent } from "@hyperbrowser/agent";

const agent = new HyperAgent();

// Create multiple pages
const page1 = await agent.newPage();
const page2 = await agent.newPage();

// Each page is independent
await page1.goto("https://news.ycombinator.com");
await page2.goto("https://reddit.com");

await agent.closeAgent();

Shared Browser, Isolated Agent History

All pages share the same browser context (cookies, storage, session state), but the agent’s history is tracked separately per page. This means:
  • Shared: Cookies, localStorage, authentication state
  • Isolated: The agent’s memory of what actions it took on each page
const agent = new HyperAgent();

const page1 = await agent.newPage();
const page2 = await agent.newPage();

// page1: Agent tracks history for this page
await page1.goto("https://example.com/login");
await page1.ai("Log in with [email protected]");

// page2: Agent has separate history, but shares the login session
await page2.goto("https://example.com/dashboard");
await page2.ai("Find my account settings");
// ^ Works because cookies are shared, but agent doesn't know about page1's actions
To pass data between pages explicitly, extract it and use it in your code:
const destination = await page1.ai("Find the recommended destination");
await page2.ai(`Search for hotels in ${destination.output}`);

Getting All Pages

const pages = await agent.getPages();
console.log(`Active pages: ${pages.length}`);

Parallel Execution

Run tasks on multiple pages simultaneously:
const agent = new HyperAgent();

const pages = await Promise.all([
  agent.newPage(),
  agent.newPage(),
  agent.newPage(),
]);

// Navigate all pages in parallel
await Promise.all([
  pages[0].goto("https://amazon.com"),
  pages[1].goto("https://ebay.com"),
  pages[2].goto("https://walmart.com"),
]);

// Search on all pages in parallel
const results = await Promise.all([
  pages[0].ai("search for 'wireless mouse' and find the cheapest option"),
  pages[1].ai("search for 'wireless mouse' and find the cheapest option"),
  pages[2].ai("search for 'wireless mouse' and find the cheapest option"),
]);

// Extract prices from all pages
const prices = await Promise.all([
  pages[0].extract("get the lowest price", z.number()),
  pages[1].extract("get the lowest price", z.number()),
  pages[2].extract("get the lowest price", z.number()),
]);

console.log("Prices:", prices);
await agent.closeAgent();