Integration

Use browser.city with Playwright (Sessions API)

Connect Playwright to a hosted browser.city session. Keep your Playwright scripts and get stealth, egress control, and predictable browser infrastructure.

If you already use Playwright, browser.city is a drop-in infrastructure layer:

  1. Create a session with POST /v1/sessions
  2. Connect with chromium.connect(endpoint, { headers: { Authorization: Bearer token } })
  3. Run your existing Playwright script

1) Set your API key

Set BROWSERCITY_API_KEY in your environment.

2) Create a session and connect

playwright.ts
import { chromium } from "playwright";const apiKey = process.env.BROWSERCITY_API_KEY!;const opts = { method: "POST", headers: { Authorization: `Bearer ${apiKey}` } };const session = await fetch("https://api.browser.city/v1/sessions", {  ...opts,  body: JSON.stringify({    browser: "chromium",    // Optional: pick an exit location and proxy type    egress: { mode: "managed", proxyType: "residential", country: "US" },    // Optional: keep sessions easy to filter in your dashboard    labels: ["playwright", "prod"],  }),}).then((r) => r.json());const browser = await chromium.connect(session.endpoint, {  headers: { Authorization: `Bearer ${session.token}` },});const context = await browser.newContext();const page = await context.newPage();await page.goto("https://example.com");

4) Practical patterns

Use Request API for pure extraction

If you don’t need interaction, the Request API is simpler than keeping a browser alive:

request.ts
const apiKey = process.env.BROWSERCITY_API_KEY!;const opts = { method: "POST", headers: { Authorization: `Bearer ${apiKey}` } };const res = await fetch("https://api.browser.city/v1/requests", {  ...opts,  body: JSON.stringify({ url: "https://example.com", markdown: true }),}).then((r) => r.json());console.log(res.content);

BYOP proxy

If you already have proxy infrastructure, bring your own:

Use egress: { mode: "byop", connectionString: "http://user:pass@host:port" } in your POST /v1/sessions body.

Pre-seed auth via storage state

If you already have cookies/localStorage from another run, inject them at session creation time via storage so you don’t re-login every time.

5) Migration note (local -> browser.city)

Most migrations are mechanical:

  • replace chromium.launch() with chromium.connect(...)
  • move your “browser boot” concerns into POST /v1/sessions (egress, fingerprint, storage)
  • keep the rest of your Playwright code unchanged
[ 06 / 06 ] — Get Started

Start building in under a minute

Free tier. No credit card. Full stealth from day one.