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, but 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 Twin a goal and it compiles the DOM into a token-efficient indexed state, plans the actions, and executes them. The successful path is frozen into a skill that replays deterministically — the resilience of a recorded script without the brittleness of hand-keyed selectors, and without re-running the LLM each time. Use Playwright when you want full manual control; use Twin when you want a goal to become durable, replayable action.
Twin is the browser execution layer your stack calls. The first run cold-compiles a skill; every similar request after that is matched from the cache and replayed deterministically, so your marginal cost per run trends toward zero.
- 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, replay, and corpus benefits 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.
Drop Twin into Playwright
Copy, paste, and swap in your Bearer key. The first run compiles a skill; repeats hit the semantic dispatch cache and replay deterministically.
# Playwright: explicit, brittle selectors you maintain by hand
page.goto("https://app.example.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": "Bearer tw_live_xxx"},
json={"goal": "Log in and download the latest invoice",
"url": "https://app.example.com/login"},
) # compile once, then run_skill replays with zero LLM callsBase URL https://twin-browser.com/api/v1 · auth Authorization: Bearer tw_live_… · MCP tools run, compile_skill, run_skill.
Connect Playwright in 4 steps
Install → configure your key → make the first call. The cache takes over from there.
- 1Pick the layer
Decide where you want goals (Twin) vs. explicit selectors (Playwright).
- 2Send a goal
POST the goal to /api/v1/run instead of scripting each step.
- 3Compile a skill
Freeze the successful run so future executions skip the LLM.
- 4Replay deterministically
Call run_skill for a fast, selector-free, LLM-free replay.
Why this stays cheap at scale
Most browser infrastructure re-runs the LLM on every execution, so cost climbs with usage. Twin compiles a task once via skill compilation, matches re-phrased requests to it, and replays without the model — so repeated workflows stop scaling with your token bill.
Playwright on Twin — common questions
Is Twin built on Playwright?
When should I keep using Playwright directly?
More ways to connect Twin
REST API
Twin’s REST API is the universal integration path: a small set of 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.
OpenAI
OpenAI’s API supports function (tool) calling: you describe a function as a JSON schema, the model decides when to call it, and your code executes it and returns the result. This is the standard way to give a GPT-class model access to an external capability.
LangChain
LangChain is a Python and JavaScript framework for building LLM applications — chains, agents, and tools. Its agent loop lets a model pick a tool, observe the result, and decide the next action, which makes browser access a natural tool to add.
Wire up Playwright in minutes
Free to start. Usage-based credits from $29/mo, with LLM cost metered and passed through at 1×.