Skip to main content
Anchor Browser offers API endpoints (also known as “agentic tools”) to simplify the usage of the browser, and enable browser utilization without any coding
PDF URLs are supported by the Get webpage content tool — the text content is extracted and returned in the same way as any other page. The Screenshot webpage tool does not support PDF URLs.
  • Perform task: Use natural language to have the browser autonomously act and perform a task.

Execute code snippet

Create a session with POST /v1/sessions, then call POST /v1/tools/execute-code with sessionId in the query string. The request body code field is an async function body with injected page, browser, context, sessionId, and anchorClient. On success, the API returns output as a JSON string of your return value.

Code example

const apiKey = process.env.ANCHOR_API_KEY;

async function createSession() {
  const res = await fetch('https://api.anchorbrowser.io/v1/sessions', {
    method: 'POST',
    headers: {
      'anchor-api-key': apiKey,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({}),
  });
  const json = await res.json();
  if (!res.ok) {
    throw new Error(`create session failed: ${res.status} ${JSON.stringify(json)}`);
  }
  return json.data.id;
}

const sessionId = await createSession();
console.log('session', sessionId);

const res = await fetch(`https://api.anchorbrowser.io/v1/tools/execute-code?sessionId=${sessionId}`, {
  method: 'POST',
  headers: {
    'anchor-api-key': apiKey,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    code: "await page.goto('https://news.ycombinator.com'); const title = await page.title(); return { title };",
  }),
});
const body = await res.json();
console.log(body);