Playwright
Connect Playwright to Lightcone cloud computers via Chrome DevTools Protocol.
Connect Playwright to Lightcone’s cloud browsers via Chrome DevTools Protocol (CDP). This gives you the full Playwright API running on Lightcone’s stealth-enabled, scalable browser infrastructure.
Install
Section titled “Install”pip install tzafon playwrightplaywright install chromiumnpm install @tzafon/lightcone playwrightnpx playwright install chromiumExample
Section titled “Example”import os, httpxfrom tzafon import Lightconefrom playwright.sync_api import sync_playwright
client = Lightcone()session = client.computers.create(kind="browser")key = os.environ["TZAFON_API_KEY"]
# Discover the browser's CDP websocket URL. Passing the key as ?token= embeds it# in the returned webSocketDebuggerUrl, so the connection is authenticated.version_url = f"https://api.tzafon.ai{session.endpoints['cdp']}/json/version"ws_url = httpx.get(version_url, params={"token": key}).json()["webSocketDebuggerUrl"]
with sync_playwright() as p: browser = p.chromium.connect_over_cdp(ws_url) page = browser.contexts[0].pages[0]
# Use the full Playwright API page.goto("https://example.com") page.fill("input[name='search']", "hello world") page.click("button[type='submit']")
# Wait for results page.wait_for_selector(".results") content = page.inner_text("body") print(content[:500])
browser.close()
client.computers.delete(session.id)import Lightcone from "@tzafon/lightcone";import { chromium } from "playwright";
const client = new Lightcone();const session = await client.computers.create({ kind: "browser" });
// Discover the browser's CDP websocket URL. Passing the key as ?token= embeds it// in the returned webSocketDebuggerUrl, so the connection is authenticated.const key = process.env.TZAFON_API_KEY;const versionUrl = `https://api.tzafon.ai${session.endpoints?.cdp}/json/version?token=${key}`;const { webSocketDebuggerUrl } = await fetch(versionUrl).then((r) => r.json());
const browser = await chromium.connectOverCDP(webSocketDebuggerUrl);const page = browser.contexts()[0].pages()[0];
await page.goto("https://example.com");await page.fill("input[name='search']", "hello world");await page.click("button[type='submit']");
await page.waitForSelector(".results");const content = await page.innerText("body");console.log(content.slice(0, 500));
await browser.close();await client.computers.delete(session.id!);Async Python
Section titled “Async Python”import os, httpxfrom tzafon import AsyncLightconefrom playwright.async_api import async_playwright
client = AsyncLightcone()session = await client.computers.create(kind="browser")key = os.environ["TZAFON_API_KEY"]
# Discover the browser's CDP websocket URL (token embedded via ?token=).version_url = f"https://api.tzafon.ai{session.endpoints['cdp']}/json/version"async with httpx.AsyncClient() as h: resp = await h.get(version_url, params={"token": key})ws_url = resp.json()["webSocketDebuggerUrl"]
async with async_playwright() as p: browser = await p.chromium.connect_over_cdp(ws_url) page = browser.contexts[0].pages[0] await page.goto("https://example.com") # ... await browser.close()
await client.computers.delete(session.id)Why use Playwright with Lightcone?
Section titled “Why use Playwright with Lightcone?”- Full Playwright API. Selectors, waiters, assertions, network interception, file uploads and downloads
- Cloud execution. No local browser needed
- Stealth and proxies. Lightcone’s anti-detection features
- Scale. Spin up hundreds of sessions in parallel
Resources
Section titled “Resources”See also
Section titled “See also”- Browser-Use: AI web agents using Playwright + Lightcone
- Computers: Lightcone’s native API (no Playwright needed)