Skip to main content
To create a browser session and connect with Playwright or Puppeteer, use Create a Session. For configuration options at create time, see Browser Sessions.
This page covers additional patterns when calling the API directly without the SDK. For integrations (Make, LangChain, CrewAI), see API Quick Start.

Session reconnection

Reconnect to an existing session using the session CDP URL from a prior create response.
const { chromium } = require('playwright-core');

(async () => {
  // sessionCdpUrl is the cdp_url returned when you created the session.
  const browser = await chromium.connectOverCDP(sessionCdpUrl);
  const page = await browser.newPage();

  // ipinfo.io/json returns IP + geolocation as JSON, so there's no dependency
  // on a specific page layout or CSS selector.
  await page.goto('https://ipinfo.io/json');
  const info = JSON.parse(await page.locator('pre').textContent());
  console.log('IP:', info.ip);
  console.log('Region:', info.region);
  console.log('City:', info.city);
  console.log('Country:', info.country);

  await browser.close();
})().catch(console.error);
import os
import json
from playwright.sync_api import sync_playwright

ANCHOR_API_KEY = os.getenv('ANCHOR_API_KEY')

with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(
        f'wss://connect.anchorbrowser.io?apiKey={ANCHOR_API_KEY}&sessionId={session_id}'
    )
    page = browser.new_page()

    # ipinfo.io/json returns IP + geolocation as JSON.
    page.goto('https://ipinfo.io/json')
    info = json.loads(page.locator('pre').text_content())
    print('IP:', info['ip'])
    print('Region:', info['region'])
    print('City:', info['city'])
    print('Country:', info['country'])

    browser.close()
Closing the Playwright/Puppeteer connection does not end the Anchor session — the cloud browser stays active until it times out or you call End Browser Session.

Next steps