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 osfrom tzafon import Lightconefrom playwright.sync_api import sync_playwright
client = Lightcone()session = client.computers.create(kind="browser")
# Build the full CDP URL from the relative endpoint pathcdp_path = session.endpoints.get("cdp") # e.g. "/computers/comp_xxx/cdp"cdp_url = f"https://api.tzafon.ai{cdp_path}"
with sync_playwright() as p: # Connect Playwright with auth headers browser = p.chromium.connect_over_cdp(cdp_url, headers={ "Authorization": f"Bearer {os.environ['TZAFON_API_KEY']}", }) 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" });
// Build the full CDP URL from the relative endpoint pathconst cdpPath = session.endpoints?.cdp; // e.g. "/computers/comp_xxx/cdp"const cdpUrl = `https://api.tzafon.ai${cdpPath}`;
const browser = await chromium.connectOverCDP(cdpUrl, { headers: { Authorization: `Bearer ${process.env.TZAFON_API_KEY}`, },});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 osfrom tzafon import AsyncLightconefrom playwright.async_api import async_playwright
client = AsyncLightcone()session = await client.computers.create(kind="browser")cdp_path = session.endpoints.get("cdp")cdp_url = f"https://api.tzafon.ai{cdp_path}"
async with async_playwright() as p: browser = await p.chromium.connect_over_cdp(cdp_url, headers={ "Authorization": f"Bearer {os.environ['TZAFON_API_KEY']}", }) 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/downloads
- Cloud execution — no local browser needed
- Stealth & 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)