An optional configuration object that can be used to customize the agent’s behavior, including Playwright launch options and LLM settings. See Agent Options for a full reference.
Sets the resolution of the screenshot that the LLM sees. This does not change the browser’s viewport size, but scales the screenshot to these dimensions. This is useful for ensuring a consistent input size for the vision model.
Executes one or more browser actions based on a natural language description. Magnitude interprets the description and determines the necessary interactions (clicks, types, scrolls, etc.).
Copy
// Simple stepawait agent.act("Click the main login button");// Step with dataawait agent.act("Enter {username} into the user field", { data: { username: "test@example.com" }});
The BrowserAgent provides a powerful extract() method that uses AI to pull structured data from a webpage based on your instructions and a Zod schema.
Copy
import { startBrowserAgent } from 'magnitude-core';import { z } from 'zod';const HackerNewsStory = z.object({ rank: z.number().describe('The story rank'), title: z.string().describe('The title of the story'), url: z.string().url().describe('The URL of the story'),});const HackerNewsSchema = z.array(HackerNewsStory);const agent = await startBrowserAgent();await agent.nav("https://news.ycombinator.com");const stories = await agent.extract( "Extract the top 5 stories from Hacker News", HackerNewsSchema);console.log(stories);await agent.stop();
A Zod schema that defines the structure of the data to be extracted. The AI will do its best to populate the fields of the schema based on the page content and your instructions.
Adding .describe() calls to your schema fields can significantly improve the accuracy of the extraction by providing more context to the AI.