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.

Playwright connection guide

How Playwright connects to remote browsers.

Playwright offers two remote connection paths. Native connections use a Playwright WebSocket endpoint. Client and server major-minor versions must match.

CDP connects only to Chromium browsers. Playwright calls this path lower fidelity. Native protocol offers the fuller Playwright experience.

Legba's preview docs publish neither connection contract. No Playwright WebSocket is currently documented. No CDP endpoint is currently documented.

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

The short version

A remote URL is not compatibility.

Remote Playwright starts with a protocol contract.

Playwright normally launches browsers on the same machine. Remote operation changes that ownership boundary. A browser server owns the browser process. Your application owns the Playwright client.

Playwright's native connect method attaches remotely. It expects a Playwright WebSocket endpoint. The BrowserServer wsEndpoint method produces it. Another provider may supply an equivalent endpoint.

The endpoint must match Playwright's protocol. Any WebSocket address is insufficient. A Chrome debugging socket is different. A browser viewing URL is also different.

Connection success proves protocol compatibility. It does not prove task reliability. State, artifacts, timeouts, and cleanup still matter. Evaluate the whole operating contract.

  • Identify the exact connection method.
  • Identify the endpoint protocol.
  • Record client and server versions.
  • Separate browser ownership from client ownership.
  • Define post-disconnection cleanup.
  • Test one representative workflow.

SourcesMicrosoft PlaywrightMicrosoft Playwright

Legba's preview documents a different contract.

Legba labels its current API public preview. Its endpoint reference remains under refinement. The organization-specific API host is still finalizing. Production decisions should reflect that status.

Current docs describe REST instance lifecycle. Teams can create isolated browser instances. They can list active instances. They can destroy completed instances.

Instance responses include an access_url. The docs describe browser access through that value. They never define a Playwright protocol. They never define a CDP protocol.

Therefore, current Playwright compatibility is undocumented. The access_url cannot establish compatibility alone. Wait for an explicit protocol contract. Recheck canonical docs before implementation.

Current Legba documentation supports limited conclusions.
FactorDocumented todayNot documented todayEngineering consequence
REST lifecycleCreate, list, and destroy instances.Playwright browser command transport.Evaluate lifecycle separately from automation.
Instance accessResponses include an access_url.Access URL protocol semantics.Never convert fields into guessed endpoints.
REST authenticationBearer API-key authentication is documented.Browser-channel authentication requirements.Do not reuse assumptions across channels.
Playwright compatibilityNo current compatibility claim exists.Native WebSocket or CDP endpoints.Keep Playwright integration unimplemented.

Current Legba documentation supports limited conclusions.

SourcesLegbaLegbaLegbaLegbaMicrosoft Playwright

Choose the connection path deliberately.

Playwright exposes two relevant remote attachment methods. They do not offer equivalent behavior. Native connect speaks Playwright's protocol. connectOverCDP speaks Chrome DevTools Protocol.

Native connect requires compatible Playwright versions. Client and server major versions must match. Minor versions must also match. Patch versions may differ.

connectOverCDP supports Chromium browsers only. Official documentation describes significantly lower fidelity. Some Playwright capabilities may behave differently. Native protocol remains the stronger default.

A provider's REST URL is neither path automatically. The provider must name the transport. It must document authentication and versions. Otherwise, compatibility remains unknown.

A decision matrix for Playwright remote connections.
FactorConnection contractBest fitRequired proofMain tradeoff
Native Playwright protocolFuller Playwright feature fidelity.A Playwright WebSocket endpoint.Matching major-minor Playwright versions.Server version constrains client upgrades.
Chrome DevTools ProtocolChromium systems exposing CDP.A documented CDP endpoint.Chromium-only browser compatibility.Playwright documents lower fidelity.
Local browser launchLocal development and controlled runners.Installed browser and runtime access.Application owns browser process lifecycle.Compute remains application-managed.
REST instance accessProvider lifecycle and browser viewing.Exact documented access semantics.No implied Playwright compatibility.Automation may require another contract.

A decision matrix for Playwright remote connections.

SourcesMicrosoft PlaywrightLegba

Use a provider-neutral native connection pattern.

The following pattern mirrors Playwright's documented method. It deliberately uses a generic environment variable. Replace it only with provider documentation. Never transform an unrelated access URL.

The client connects before creating a context. That context receives its own pages. The example closes context resources explicitly. It then closes the connected browser object.

This example is provider-neutral. It uses a placeholder endpoint. It was not tested against Legba. It does not prove Legba compatibility.

Production code needs provider-specific lifecycle handling. It also needs retries and artifact capture. Those details depend on published contracts. Keep them outside generic connection helpers.

  • Keep endpoint values outside source code.
  • Match client and server versions.
  • Create explicit browser contexts.
  • Close contexts before disconnecting.
  • Separate provider resource cleanup.
  • Never label this Legba-compatible.
Provider-neutral native Playwright connection example.
import { chromium } from "playwright"

const browser = await chromium.connect(
  process.env.PLAYWRIGHT_WS_ENDPOINT!,
)
const context = await browser.newContext()
const page = await context.newPage()

await page.goto("https://example.com")
await context.close()
await browser.close()

SourcesMicrosoft PlaywrightMicrosoft PlaywrightMicrosoft Playwright

Treat browser state as sensitive infrastructure.

Playwright browser contexts provide independent sessions. They isolate cookies and local storage. Multiple contexts can share one browser. Each context still needs explicit ownership.

Authentication state can reduce repeated login work. Playwright stores reusable state through storageState. That file may contain sensitive cookies. It may also contain sensitive headers.

Playwright recommends keeping state outside repositories. Add its directory to version-control exclusions. Delete expired state when appropriate. Never expose reusable state through client bundles.

Remote providers add another storage boundary. Ask where context data resides. Ask whether profiles persist after termination. Ask how deletion is verified. Document every answer before reuse.

State choices change security and repeatability.
FactorState choiceOperational benefitRequired safeguard
Fresh contextStarts with isolated browser state.Improves task repeatability.Close every context explicitly.
Stored authentication stateAvoids repeated login setup.Reduces test preparation time.Protect cookies and sensitive headers.
Provider profileMay preserve browser state remotely.Depends entirely on provider contracts.Verify retention and deletion behavior.
Shared default contextMay expose existing browser state.Changes isolation assumptions.Inspect provider context semantics first.

State choices change security and repeatability.

SourcesMicrosoft PlaywrightMicrosoft PlaywrightLegba

Design artifacts before failures happen.

Remote debugging needs durable evidence. A local stack trace may be insufficient. Browser actions happened elsewhere. Network timing and page state can disappear quickly.

Playwright tracing records browser operations. Trace Viewer exposes actions and metadata. Traces can include screenshots and snapshots. Their contents may include sensitive application data.

Playwright Test supports retry-focused tracing. Official guidance recommends tracing the first retry. That balances evidence against performance costs. Plain library usage requires explicit tracing calls.

Artifact transfer remains provider-specific. Ask where trace files are written. Ask whether disconnection preserves them. Ask when downloads become available. Test retrieval during partial failures.

  1. 01

    Choose required failure evidence.

    List traces, logs, screenshots, and downloads. Assign retention needs.

  2. 02

    Enable artifacts intentionally.

    Capture evidence around representative failures. Avoid unbounded collection.

  3. 03

    Interrupt the client process.

    Confirm provider-side artifacts remain retrievable. Record missing evidence.

  4. 04

    Review sensitive contents.

    Treat traces as potentially sensitive. Restrict storage and sharing.

SourcesMicrosoft PlaywrightMicrosoft Playwright

Separate connection cleanup from resource cleanup.

Playwright exposes browser and context lifecycle methods. The browser close method clears connected contexts. It then disconnects the client. Close contexts first for orderly artifact flushing.

Provider infrastructure may have another lifecycle. A disconnected client may leave resources active. The provider's REST contract must own termination. Browser closure never proves provider termination.

Failures can occur between every cleanup step. Context closure can fail. Client disconnection can race network loss. Provider termination can also fail independently.

Use resource identifiers for reconciliation. List remaining resources after interruptions. Retry only documented safe operations. Confirm a final terminated state. Keep browser errors and lifecycle errors separate.

Cleanup layers have separate owners.
FactorCleanup layerResponsible interfaceVerification evidence
Page workApplication and Playwright page APIs.Finish outputs before context closure.Required artifacts are retrievable.
Browser contextPlaywright BrowserContext owns pages.Close the context explicitly.Context pages are closed.
Client connectionConnected Browser owns client attachment.Close after context cleanup.The client becomes disconnected.
Provider resourceProvider lifecycle contract owns infrastructure.Call documented termination separately.Resource status confirms termination.

Cleanup layers have separate owners.

SourcesMicrosoft PlaywrightMicrosoft PlaywrightLegbaLegba

Prove the contract before migration.

Begin with one production-shaped Playwright task. Include navigation and authentication. Include expected outputs and artifacts. Include a normal failure path.

Write compatibility requirements before choosing providers. Name the desired connection method. Name the supported browser engines. Name acceptable version constraints.

Legba currently supports lifecycle research only. Its preview docs lack Playwright protocol details. They also lack CDP endpoint details. Current evidence cannot justify implementation.

Return after published compatibility appears. Then test the exact documented endpoint. Pin compatible Playwright versions. Recheck documentation before each upgrade. Keep guessed endpoints out of production.

  1. 01

    Define the protocol requirement.

    Choose native Playwright or CDP. Record required browser engines.

  2. 02

    Require published provider evidence.

    Verify endpoint type, authentication, and versions. Record remaining unknowns.

  3. 03

    Run one representative task.

    Exercise state, artifacts, downloads, and cleanup. Preserve failure evidence.

  4. 04

    Interrupt every lifecycle layer.

    Test connection loss and client failure. Reconcile provider resources afterward.

  5. 05

    Review the current preview.

    Recheck canonical Legba documentation. Wait for explicit Playwright compatibility.

SourcesLegbaLegbaLegbaMicrosoft Playwright

FAQs.

References

  1. 01
  2. 02
  3. 03
  4. 04
  5. 05
  6. 06
    Playwright BrowserTypeMicrosoft Playwright
  7. 07
    Playwright BrowserMicrosoft Playwright
  8. 08
    Playwright BrowserContextMicrosoft Playwright
  9. 09
    Playwright authenticationMicrosoft Playwright
  10. 10
    Playwright Trace ViewerMicrosoft Playwright

Keep exploring