Skip to content

Usage

Minimal example: run an agent task

Node.js

javascript
import AnchorClient from "anchorbrowser";

const anchorClient = new AnchorClient({
  apiKey: process.env.ANCHOR_API_KEY,
});

(async () => {
  const result = await anchorClient.agent.task(
    "go to news.ycombinator.com and get the title of the first story"
  );
  console.log("Task result:", result);
})();

Python

python
import os
from anchorbrowser import Anchorbrowser

anchor_client = Anchorbrowser(
    api_key=os.getenv("ANCHOR_API_KEY")
)

result = anchor_client.agent.task(
    "go to news.ycombinator.com and get the title of the first story"
)
print("Task result:", result)

How it works

  1. You call agent.task() with a natural-language instruction.
  2. Anchor Browser spins up a humanized Chromium instance in the cloud.
  3. Its built-in agent navigates the page, extracts data, or performs actions.
  4. The result is returned as structured output to your code.
  5. The cloud browser session is closed automatically.

Playwright / Puppeteer (bring-your-own-automation)

If you prefer direct browser control instead of the agent API, Anchor Browser exposes a standard CDP (Chrome DevTools Protocol) endpoint. Connect your existing Playwright or Puppeteer scripts by swapping the browser launch URL:

javascript
import { chromium } from "playwright";

const browser = await chromium.connectOverCDP(
  `wss://connect.anchorbrowser.io?apiKey=${process.env.ANCHOR_API_KEY}`
);
const page = await browser.newPage();
await page.goto("https://news.ycombinator.com");
const title = await page.title();
console.log(title);
await browser.close();

Parallel sessions

The SDK is stateless; call agent.task() concurrently from multiple async workers to run sessions in parallel up to your plan's concurrency limit.

javascript
const tasks = [
  "get the top story from news.ycombinator.com",
  "get the top story from reddit.com/r/programming",
];

const results = await Promise.all(
  tasks.map((t) => anchorClient.agent.task(t))
);
console.log(results);

Further reading