Documentation Index
Fetch the complete documentation index at: https://docs.anchorbrowser.io/llms.txt
Use this file to discover all available pages before exploring further.
This page is a quick start using code. For a quick start using an Integration (Make, Langchain, CrewAI, etc.) click here.
Create a session via API
Also available by the live playgroundconst axios = require("axios");
(async () => {
const session = await axios.post("https://api.anchorbrowser.io/v1/sessions", {}, {
headers: {
"anchor-api-key": process.env.ANCHOR_API_KEY,
"Content-Type": "application/json"
}
});
const cdp_url = session.data.data.cdp_url;
console.log("Session's CDP_URL for later use\n", cdp_url);
})().catch(console.error);
Run sample code
const { chromium } = require("playwright-core");
(async () => {
// Connect to the session
const browser = await chromium.connectOverCDP(cdp_url);
const page = await browser.newPage();
// Navigate to Anchor Browser's website
await page.goto("https://anchorbrowser.io");
console.log("Page title:", await page.title());
await browser.close();
})().catch(console.error);
Advanced browser configuration
Anchor Browser supports different configurations of the browser session (see API reference for all options).
Some of the most common configurations are:To use a browser with a specific configuration, first create a browser session with the desired configuration.const axios = require("axios");
(async () => {
const browserConfiguration = {
session: {
"recording": { "active": false }, // Default is true
// Proxy configuration
proxy: {
active: true,
country_code: "it"
},
// Session lifetime management
"timeout": {
"max_duration": 1, // 1 minute
"idle_timeout": 1 // 1 minute
}
}
};
const response = await axios.post(
"https://api.anchorbrowser.io/v1/sessions",
browserConfiguration,
{ headers: {
"anchor-api-key": process.env.ANCHOR_API_KEY,
"Content-Type": "application/json",
},
});
const session = response.data.data;
console.log("Session created:", session.id); // Keep this ID for later use
})().catch(console.error);
Session reconnection
Reconnect to an existing session using the session CDP Url.const { chromium } = require("playwright-core");
const ANCHOR_API_KEY = process.env.ANCHOR_API_KEY;
(async () => {
const browser = await chromium.connectOverCDP(sessionCdpUrl);
const page = await browser.newPage();
// Check the IP address
await page.goto("https://www.whatismyip.com/");
await page.waitForTimeout(10000)
console.log(await page.textContent('#region-state'))
// Close browser but session remains active
await browser.close();
})().catch(console.error);