Browser library integration
Twin Browser + Playwright
Playwright is a browser automation library that drives Chromium, Firefox and WebKit with explicit, imperative commands — click this selector, fill that field, assert this text. It is precise and fast, and every selector is hand-written and brittle to page changes.
How Twin plugs into Playwright
Twin sits one level above Playwright-style scripting: instead of authoring and maintaining selectors, you hand it a goal and it compiles the page into a token-efficient indexed state, plans the actions, and executes them. The successful path is frozen into a skill that replays deterministically — the repeatability of a recorded script without the hand-keyed selectors, and without re-planning each time. Keep Playwright where you want full manual control; reach for Twin where a goal should survive a redesign.
Twin is the browser execution layer your stack calls. The first run cold-compiles a skill via skill compilation; every similar request after that is matched from the cache and replayed deterministically, so your marginal cost per run trends toward zero rather than climbing with usage.
- Receive goal from Playwrightdone
- Compile DOM → token-efficient indexed statedone
- Match the semantic dispatch cacherunning
- Replay compiled skill — 0 LLM callsqueued
What you get through Playwright
Every integration is a thin wrapper over the same execution layer, so the cache, the replay, and the corpus apply no matter how you call in.
Semantic dispatch cache
A re-phrased goal fuzzy-matches an already-compiled skill, so most calls never touch the LLM.
Deterministic replay
A compiled skill replays the exact action path with zero LLM calls — fast, repeatable, cheap.
Cross-tenant skill corpus
A skill compiled once can be safely reused across tenants, so the hit rate climbs as the network runs.
One Bearer key
Auth, usage-based billing, and an audit log run on every call — the same key works from every integration.
Wire it up
Drop Twin into Playwright.
Copy, paste, and swap in your Bearer key. The first run compiles a skill; repeats match the semantic dispatch cache and replay deterministically.
# Playwright: explicit selectors you maintain by hand
page.goto("https://app.acme.com/login")
page.fill("#email", user)
page.fill("#password", pw)
page.click("button[type=submit]")
page.click("text=Download invoice")
# Twin: a goal that compiles into a replayable skill
requests.post(
"https://twin-browser.com/api/v1/run",
headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
json={
"url": "https://app.acme.com/login",
"prompt": "Sign in and download the latest invoice",
"success": {"kind": "textVisible", "value": "Invoice"},
},
)
# then POST /api/v1/skills once, and replay by name with no model in the loopBase URL https://twin-browser.com/api/v1 · auth Authorization: Bearer ab_live_… · over MCP the same engine is run_goal, compile_skill and run_skill — the full tool table.
Pick the layer
Decide which flows want explicit selectors (Playwright) and which want a goal (Twin).
Send a goal
POST { url, prompt, success } to /api/v1/run instead of scripting each step.
Compile a skill
POST /api/v1/skills to freeze the successful run so future executions skip the planning.
Replay deterministically
POST /api/v1/skills/{name}/run for a fast, selector-free replay with no model in the loop.
FAQ
Playwright on Twin — common questions
Is Twin built on Playwright?
When should I keep using Playwright directly?
Related
More ways to connect Twin
Node.js & TypeScript
Node is the other half of the agent ecosystem — the Vercel AI SDK, LangChain.js, and the OpenAI and Anthropic TypeScript SDKs all run here, and it is where most production API routes and background workers live.
Python
Python is where most agent code lives — LangChain, LlamaIndex, CrewAI, AutoGen, Pydantic AI and the OpenAI and Anthropic SDKs are all Python-first. Anything you can express as a function call, an agent can be given as a tool.
REST API
Twin’s REST API is the universal integration path: HTTPS endpoints under `/api/v1/*`, authenticated with a Bearer key. Any language that can make an HTTP request can drive the browser execution layer — no SDK required, and none is published.
Wire up Playwright in minutes.
Free to start. Usage-based credits from $29/mo — each call billed the higher of its flat action price or its metered cost.