Skip to main content
public preview

These docs are a public preview. The endpoint reference is still firming up as the API host is finalized.

Browser API contract guide

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.

Published byLegbaReviewed byAakash HarishSecurity Research Contributor, LegbaReviewed 2026-08-28 · Updated 2026-08-28

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.

SourcesLegbaLegbaMicrosoft PlaywrightGoogle Puppeteer

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.

SourcesLegbaLegbaLegbaLegba

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.

A lifecycle matrix for agent browser infrastructure.
FactorRequired contractSuccess evidenceFailure question
ProvisionCreate one isolated browser resource.Receive a stable resource identifier.How are rejected requests represented?
ReadinessKnow when browser work may begin.Observe an explicit ready state.How are startup delays surfaced?
ConnectObtain a documented browser connection contract.Complete one authenticated connection.Which protocol and versions apply?
ExecuteOpen pages and perform browser actions.Complete one representative agent task.Which timeouts govern browser commands?
ObserveCapture enough evidence for diagnosis.Review one failed task afterward.Which artifacts survive disconnection?
TerminateRelease 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.

A contract matrix for browser API evaluation.
FactorRequired answerWhy it mattersCurrent Legba status
Lifecycle interfaceCreate, inspect, and terminate resources.Agents need deterministic resource ownership.REST instance lifecycle is documented.
Browser protocolName the exact automation protocol.Client libraries depend on protocol compatibility.No automation protocol is documented.
Connection authenticationDefine browser-channel authentication requirements.REST credentials may not authorize WebSockets.Only REST API-key authentication is documented.
State boundaryDefine cookies, storage, and context isolation.State reuse changes security and reliability.No Playwright or Puppeteer state contract exists.
Artifact ownershipDefine logs, traces, screenshots, and downloads.Operators need evidence after failures.Review current canonical docs directly.
Cleanup behaviorDefine disconnect and termination separately.Client exit may leave resources running.REST destruction is documented.
Error modelPublish statuses and structured error responses.Agents need deterministic recovery paths.A REST error structure is documented.

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.

Connection labels describe different technical contracts.
FactorTypical purposeCompatibility requirementKey limitation
REST lifecycleProvision and terminate infrastructure resources.Follow the provider's HTTP contract.It may expose no browser protocol.
Playwright protocolAttach Playwright to a browser server.Match client and server major-minor versions.A Playwright WebSocket is required.
CDPAttach through Chrome DevTools Protocol.Use a documented CDP endpoint.Playwright supports Chromium only.
Puppeteer connectionAttach 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.

SourcesLegbaMicrosoft PlaywrightGoogle Puppeteer

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.

Failure classes need different recovery actions.
FactorLikely ownerRecovery actionRequired evidence
Provisioning failureThe lifecycle API owns this stage.Retry only documented safe requests.Capture status and structured error details.
Readiness timeoutThe provider defines readiness semantics.Inspect resource status before replacement.Record timestamps and resource identifiers.
Connection failureThe browser protocol owns attachment.Validate endpoint, credentials, and versions.Capture the protocol-level failure.
Task failureThe application owns browser decisions.Collect artifacts before cleanup.Preserve browser and application logs.
Cleanup failureLifecycle 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.

  1. 01

    Choose one representative task.

    Include login, navigation, output, and cleanup. Preserve normal failure conditions.

  2. 02

    Write the required contracts.

    Separate lifecycle, browser protocol, and state. Assign an owner each.

  3. 03

    Verify published compatibility.

    Require exact protocol and version documentation. Record every remaining unknown.

  4. 04

    Exercise partial failures.

    Interrupt connection and task execution. Confirm cleanup and diagnostic evidence.

  5. 05

    Recheck preview documentation.

    Confirm the current host and contract. Update assumptions before production.

SourcesLegbaLegbaLegbaLegbaLegba

FAQs.

References

  1. 01
  2. 02
  3. 03
  4. 04
  5. 05
  6. 06
    Playwright BrowserTypeMicrosoft Playwright
  7. 07
    Playwright BrowserContextMicrosoft Playwright
  8. 08
  9. 09
    Puppeteer ConnectOptionsGoogle Puppeteer
  10. 10

Keep exploring