1

Fetch API Key

In Anchor UI, copy your API key

2

Install playwright

npm i playwright-core
3

Run sample code

If you don’t have access to code running, consider using the live playground

The following example demonstrates how to start the browser and navigate to a website

import { chromium } from "playwright-core";

const ANCHOR_API_KEY = process.env.ANCHOR_API_KEY;

const browser = await chromium.connectOverCDP(`wss://connect.anchorbrowser.io?apiKey=${ANCHOR_API_KEY}`);
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();
4

Alter the browser configuration

Anchor Browser supports different configurations of the browser session, such as network configuration, identity profiles, termination and more.

To use a browser with a specific configuration, first create a browser session with the desired configuration, then connect to the session using the session URL.

import { chromium } from "playwright-core";
import axios from "axios";

const ANCHOR_API_KEY = process.env.ANCHOR_API_KEY;

const browserConfiguration = {};

const response = await axios.post("https://api.anchorbrowser.io/v1/sessions", browserConfiguration, {
  headers: {
    "anchor-api-key": ANCHOR_API_KEY,
    "Content-Type": "application/json",
  },
});

const session = response.data.data;

const browser = await chromium.connectOverCDP(`wss://connect.anchorbrowser.io?apiKey=${ANCHOR_API_KEY}&sessionId=${session.id}`);
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();