Skip to main content
Anchor Browser delivers a state-of-the-art 89% Score on the industry-standard benchmark WebVoyager, leveraging browser-use as a core component of the automation capability.

The agent task method

Anchor Browser provides within its SDK the agent.task method that enables natural language control over web browsing sessions. This capability allows you to automate complex web tasks without coding the whole flow.
Looking for Tasks? Visit the Tasks Page.

Code Example

import Anchorbrowser from 'anchorbrowser';

(async () => {
  const anchorClient = new Anchorbrowser({
    apiKey: process.env.ANCHORBROWSER_API_KEY
  });

  const response = await anchorClient.agent.task(
    'Extract the main heading',                     // Required
    {
      taskOptions: {
        url: 'https://example.com',                 // Either sessionId or url is required
        humanIntervention: true,                    // Allow human intervention during task execution
        detectElements: true,                       // Improves the agent's ability to identify and interact with UI elements
        maxSteps: 40,                               // Maximum number of steps the agent can take
        agent: 'browser-use',                       // browser-use (default), openai-cua, or gemini-computer-use
        provider: 'groq',                           // For browser-use agent only, openai, gemini, groq, azure, xai
        model: 'openai/gpt-oss-120b',               // For browser-use agent only, see model list below
        extendedSystemMessage: 'Focus on extracting the main heading from the page',
        secretValues: {                             // Secret values to pass to the agent for secure credential handling
          API_KEY: 'your-secret-key'
        }
      }
    }
  );

  console.log(response);
})();

Structured Output

The AI object can also be used to extract structured data from the browser. This is done by providing a JSON schema to the AI object, which will then return the structured data. The following demonstrates using Zod and Pydantic to utilize the structured output capability.
// Create a browser session and get references
const browser = await anchorClient.browser.create();
const context = browser.contexts()[0];
const page = context.pages()[0];
const ai = context.serviceWorkers()[0]; // Get the AI service worker

// Define the expected output structure using Zod schema
const outputSchema = z.object({
  nodes_cpu_usage: z.array(
    z.object({
      node: z.string(),           // Node name
      cluster: z.string(),        // Cluster identifier
      cpu_avg_percentage: z.number(), // CPU usage percentage
    })
  )
});

// Create task payload with structured output schema
const taskPayload = {
  output_schema: z.toJSONSchema(outputSchema);,      // Define expected output structure
  prompt: 'Collect the node names and their CPU average %',
};

// Navigate to the target page
await page.goto("https://play.grafana.org/a/grafana-k8s-app/navigation/nodes?from=now-1h&to=now&refresh=1m");

// Execute the AI task with structured output
const result = await ai.evaluate(JSON.stringify(taskPayload));
console.info(result);

// Clean up browser resources
await browser.close();

Secret Values

Securely pass credentials and sensitive data to AI agents during task execution. Secret values are not logged and automatically cleaned up after completion.

Learn more about Secret Values →

Available Models For Browser-Use