How to evaluate a browser API for AI agents.
An agent browser API needs two contracts. One controls compute lifecycle. The other controls browser execution. A provider may expose one or both.
Legba currently documents a public-preview REST lifecycle. It creates, lists, and destroys isolated instances. Responses include an access_url.
The docs do not document Playwright protocol. They do not document CDP endpoints. They do not document Puppeteer WebSockets. No drop-in compatibility is currently claimed.
The short version
The browser is easy. The contract is hard.
A browser API has two control planes.
Browser infrastructure looks simple from application code. An agent requests a browser. It performs browser work. Then the application releases resources.
That sequence hides two independent contracts. The lifecycle contract provisions and terminates compute. The browser contract carries automation commands. These contracts often use different protocols.
REST commonly controls lifecycle resources. WebSockets commonly carry browser commands. CDP is one browser-control protocol. Playwright also defines its own protocol.
A returned URL proves only documented access. It does not prove automation compatibility. The URL scheme and semantics matter. Authentication requirements also matter.
Understand Legba's current preview boundary.
Legba labels its API documentation public preview. The endpoint reference is still firming up. The organization-specific host is also finalizing. Production assumptions should reflect that status.
Current documentation covers REST instance lifecycle. Teams can create isolated browser instances. They can list running instances. They can destroy completed instances.
Documented instance responses include an access_url. The docs describe browser access through that field. They do not define its automation protocol. That omission remains a real boundary.
Current docs never promise Playwright compatibility. They never publish a Playwright WebSocket. They never publish a CDP endpoint. They never publish a Puppeteer WebSocket.
- Treat every endpoint as preview material.
- Obtain the assigned organization host.
- Use current authentication documentation.
- Read the instance lifecycle reference.
- Do not infer browser protocols.
- Recheck documentation before production adoption.
Map the complete browser lifecycle.
Most browser failures occur between obvious steps. Creation can succeed before readiness. Connection can succeed before navigation. Work can finish before cleanup.
A reliable contract defines every transition. Each transition needs success evidence. Each transition also needs failure evidence. Ownership must remain unambiguous.
The matrix separates lifecycle stages. It avoids vendor-specific endpoint assumptions. Apply it to every shortlisted provider. Record unknowns instead of guessing.
| Factor | Required contract | Success evidence | Failure question |
|---|---|---|---|
| Provision | Create one isolated browser resource. | Receive a stable resource identifier. | How are rejected requests represented? |
| Readiness | Know when browser work may begin. | Observe an explicit ready state. | How are startup delays surfaced? |
| Connect | Obtain a documented browser connection contract. | Complete one authenticated connection. | Which protocol and versions apply? |
| Execute | Open pages and perform browser actions. | Complete one representative agent task. | Which timeouts govern browser commands? |
| Observe | Capture enough evidence for diagnosis. | Review one failed task afterward. | Which artifacts survive disconnection? |
| Terminate | Release browser and infrastructure resources. | Confirm the resource no longer runs. | What happens after client failure? |
A lifecycle matrix for agent browser infrastructure.
SourcesLegbaLegbaLegbaMicrosoft PlaywrightGoogle PuppeteerGoogle PuppeteerMicrosoft Playwright
Evaluate the contract before the demo.
A polished demonstration proves one happy path. Production requires a stable written contract. That contract spans more than browser commands. It includes ownership, limits, and cleanup.
The matrix turns vague platform claims into questions. Every answer needs published evidence. A sales answer can guide testing. It should not replace documentation.
Use the matrix before implementation starts. Missing mandatory answers should block migration. Optional unknowns can remain tracked. Their uncertainty should remain priced.
| Factor | Required answer | Why it matters | Current Legba status |
|---|---|---|---|
| Lifecycle interface | Create, inspect, and terminate resources. | Agents need deterministic resource ownership. | REST instance lifecycle is documented. |
| Browser protocol | Name the exact automation protocol. | Client libraries depend on protocol compatibility. | No automation protocol is documented. |
| Connection authentication | Define browser-channel authentication requirements. | REST credentials may not authorize WebSockets. | Only REST API-key authentication is documented. |
| State boundary | Define cookies, storage, and context isolation. | State reuse changes security and reliability. | No Playwright or Puppeteer state contract exists. |
| Artifact ownership | Define logs, traces, screenshots, and downloads. | Operators need evidence after failures. | Review current canonical docs directly. |
| Cleanup behavior | Define disconnect and termination separately. | Client exit may leave resources running. | REST destruction is documented. |
| Error model | Publish statuses and structured error responses. | Agents need deterministic recovery paths. | A REST error structure is documented. |
A contract matrix for browser API evaluation.
SourcesLegbaLegbaMicrosoft PlaywrightGoogle PuppeteerLegbaGoogle PuppeteerMicrosoft PlaywrightGoogle PuppeteerLegba
Keep interface layers separate.
A browser API may expose several interfaces. REST can manage infrastructure resources. Playwright protocol carries Playwright commands. CDP carries Chromium debugging commands.
Puppeteer commonly connects through a browser WebSocket. Its ConnectOptions define supported connection inputs. A browserWSEndpoint identifies the existing browser. Browser ownership remains a separate concern.
Playwright's native connection has version constraints. Client and server major versions must match. Minor versions must match too. Patch versions can differ safely.
Playwright CDP connections are Chromium-only. Official docs call them lower fidelity. Advanced Playwright features may work differently. Native Playwright protocol remains the preferred path.
| Factor | Typical purpose | Compatibility requirement | Key limitation |
|---|---|---|---|
| REST lifecycle | Provision and terminate infrastructure resources. | Follow the provider's HTTP contract. | It may expose no browser protocol. |
| Playwright protocol | Attach Playwright to a browser server. | Match client and server major-minor versions. | A Playwright WebSocket is required. |
| CDP | Attach through Chrome DevTools Protocol. | Use a documented CDP endpoint. | Playwright supports Chromium only. |
| Puppeteer connection | Attach Puppeteer to an existing browser. | Pass valid ConnectOptions. | Disconnection does not terminate browsers. |
Connection labels describe different technical contracts.
SourcesLegbaLegbaMicrosoft PlaywrightGoogle PuppeteerGoogle PuppeteerGoogle Puppeteer
State deserves its own contract.
Browser state includes cookies and local storage. It may also include authentication headers. Reusing that state can reduce repeated logins. It also expands credential exposure.
Playwright contexts isolate independent browser sessions. Closing a context closes its pages. Puppeteer contexts also isolate cookies and storage. Their exact APIs still differ.
Provider-side state adds another layer. A provider may persist profiles across instances. It may scope them to organizations. Those behaviors need explicit documentation.
Legba currently documents REST API-key authentication. Keys belong outside client-side code. The browser-channel authentication contract remains undocumented. Never infer it from REST authentication.
- Keep API keys server-side.
- Separate REST and browser credentials.
- Create one state boundary per task.
- Document any reusable state explicitly.
- Define deletion and expiration behavior.
- Test cross-task state isolation.
Design failure handling before scale.
Agents encounter partial failures constantly. Infrastructure can exist before browser readiness. Browser commands can timeout during active instances. Client processes can stop before cleanup.
A strong API distinguishes these failures. It exposes structured error codes. It records the affected resource identifier. It makes retry safety understandable.
Legba documents REST error response structure. It also documents common HTTP statuses. That helps lifecycle recovery. Browser-protocol failures remain outside current documentation.
Observation must survive the failing client. Ask where logs and artifacts live. Ask when they become available. Ask how long they remain accessible.
| Factor | Likely owner | Recovery action | Required evidence |
|---|---|---|---|
| Provisioning failure | The lifecycle API owns this stage. | Retry only documented safe requests. | Capture status and structured error details. |
| Readiness timeout | The provider defines readiness semantics. | Inspect resource status before replacement. | Record timestamps and resource identifiers. |
| Connection failure | The browser protocol owns attachment. | Validate endpoint, credentials, and versions. | Capture the protocol-level failure. |
| Task failure | The application owns browser decisions. | Collect artifacts before cleanup. | Preserve browser and application logs. |
| Cleanup failure | Lifecycle ownership must remain explicit. | Reconcile resources through the lifecycle API. | Confirm final termination state. |
Failure classes need different recovery actions.
SourcesLegbaLegbaMicrosoft PlaywrightGoogle PuppeteerMicrosoft PlaywrightGoogle Puppeteer
Evaluate one complete contract.
Start with one representative agent task. Include normal authentication and state. Include normal artifacts and failure paths. Avoid a polished toy demonstration.
Write acceptance criteria before connecting anything. Name the required browser protocol. Name the required lifecycle operations. Name the required cleanup evidence.
Legba's preview docs support lifecycle evaluation today. They do not support Playwright compatibility claims. They do not support Puppeteer compatibility claims. Wait for published protocol details.
Review canonical documentation before implementation. Preview contracts can change. Keep version and host assumptions configurable internally. Do not publish guessed endpoints.
- 01
Choose one representative task.
Include login, navigation, output, and cleanup. Preserve normal failure conditions.
- 02
Write the required contracts.
Separate lifecycle, browser protocol, and state. Assign an owner each.
- 03
Verify published compatibility.
Require exact protocol and version documentation. Record every remaining unknown.
- 04
Exercise partial failures.
Interrupt connection and task execution. Confirm cleanup and diagnostic evidence.
- 05
Recheck preview documentation.
Confirm the current host and contract. Update assumptions before production.
FAQs.
References
- 01
- 02Legba API quickstartLegba
- 03Legba Instances APILegba
- 04
- 05Legba API errorsLegba
- 06Playwright BrowserTypeMicrosoft Playwright
- 07Playwright BrowserContextMicrosoft Playwright
- 08Puppeteer connect functionGoogle Puppeteer
- 09Puppeteer ConnectOptionsGoogle Puppeteer
- 10Puppeteer browser managementGoogle Puppeteer