A scraper that collects every Science Fiction book from Books to Scrape, used as an example of running the e2e agent outside a test run.
The scraper is a single script, scraper/scrape-sci-fi.ts. It launches a browser with @e2e-dev/core and @e2e-dev/web, then lets an agent do the work:
- Navigation uses
agent.actto open the category and go to the next page of results. After each step, an exact locator waits for the expected heading or page number to confirm the agent ended up in the right place. - Extraction uses
agent.extractwith a Zod schema. On each listing page it reads the book URLs, the result count, and whether there's a next page. On each book page it reads the title, price, stock, UPC, rating, review count, and description. The rating is shown as stars, so book pages are read withvision: true. - Output goes to
output/science-fiction.json. The script checks that it found as many books as the category says it has.
The script has no CSS selectors: the agent finds links and reads values from what's on the page.
Each agent.act step is recorded in .scraper/cache the first time it runs. Later runs replay the recording without calling the model. agent.extract calls the model on every run, because the page content is what you're after.
{
"category": "Science Fiction",
"scrapedAt": "2026-11-27T13:46:46.220Z",
"books": [
{
"title": "Join",
"price": 35.67,
"inStock": true,
"upc": "18ad3ed896c7ce05",
"rating": 5,
"stockCount": 16,
"numberOfReviews": 0,
"description": "What if you could live multiple lives simultaneously, …",
"url": "https://books.toscrape.com/catalogue/join_902/index.html"
}
]
}You need Node.js 24 or later, which runs the TypeScript script directly.
npm install
npm run scrapeThe agent model goes through the Vercel AI Gateway, so set AI_GATEWAY_API_KEY (or link a Vercel project). To use a different model, set SCRAPER_MODEL to a gateway model ID (the default is openai/gpt-6-luna-fast).
To watch the browser while it scrapes:
npm run scrape:headedTo scrape another category, change CATEGORY and OUTPUT at the top of the script.
| Command | Description |
|---|---|
npm run scrape |
Scrape the Science Fiction books |
npm run scrape:headed |
Scrape with a visible browser |
npm run format |
Format with Prettier |