Skip to main content
published reference

Based on the published Legba skill. Verified 2026-10-28. Requests require your API key and available plan capacity.

Puppeteer connection guide

How Puppeteer connects to remote browsers.

Puppeteer's connect method attaches to existing browsers. It accepts a ConnectOptions object. browserWSEndpoint is a common remote attachment input.

The browser disconnect method detaches Puppeteer. It does not close the browser. Existing pages also remain open.

Legba's hosted browser uses HTTP actions and MCP tools. The source publishes no Puppeteer WebSocket. Direct Puppeteer attachment remains undocumented.

Written byLegbaReviewed byAakash HarishSecurity Research Contributor, LegbaReviewed 2026-10-28 · Updated 2026-10-28

The short version

Attachment is simple. Ownership is not.

Remote Puppeteer requires an attachment contract.

Puppeteer usually launches a browser directly. Remote systems separate browser ownership from client ownership. A provider starts the browser process. Your application attaches through Puppeteer.

Puppeteer's connect method performs that attachment. It accepts a ConnectOptions object. The object can include browserWSEndpoint. That value identifies a running browser's WebSocket endpoint.

The browser wsEndpoint method returns this endpoint. Another Puppeteer client can use it. The endpoint follows a browser debugging WebSocket format. It is not an arbitrary viewing URL.

A successful connection proves attachment compatibility. It does not prove infrastructure cleanup. It also does not prove state isolation. Those contracts need separate evidence.

  • Identify the exact connection input.
  • Verify endpoint discovery and authentication.
  • Separate browser and client ownership.
  • Define context isolation behavior.
  • Define disconnect and close semantics.
  • Test provider resource termination.

SourcesPuppeteer connect functionPuppeteer ConnectOptionsPuppeteer Browser wsEndpointPuppeteer browser management

Legba documents its own browser control contract.

Legba publishes HTTP session operations and MCP tools. Its dashboard issues the required bearer key. The skill includes a runnable session client.

Create a session with kind, country, and browser. Inspect the current session before creating another. Delete the session when work finishes.

Hosted agent browsers expose navigation, reading, clicks, and screenshots. Human handoff returns a private view_url. That link lets a person share the session.

The source publishes no remote Playwright or CDP endpoint. Local Playwright routing remains a separate skill workflow. Puppeteer attachment is not documented.

The published interfaces establish distinct compatibility boundaries.
FactorDocumented todayNot documented todayEngineering consequence
REST lifecycleSession creation, current lookup, and deletion.Remote Playwright or Puppeteer attachment.Evaluate lifecycle separately from attachment.
Human browser accessThe view_url opens the hosted browser.Any CDP or Playwright transport behind that URL.Never derive an automation endpoint from viewing links.
REST authenticationBearer authentication authorizes sessions and MCP.Separate remote attachment credentials.Follow each documented interface independently.
Puppeteer compatibilityThe cited docs make no compatibility claim.WebSocket or browser URL inputs.Keep Puppeteer integration unimplemented.

The published interfaces establish distinct compatibility boundaries.

SourcesLegba published skill and session contractPuppeteer ConnectOptions

SourcesLegba published session client

Choose the attachment input deliberately.

ConnectOptions supports several attachment inputs. browserWSEndpoint directly identifies a debugging socket. browserURL supplies another documented option. A custom transport supports specialized connections.

These inputs are not interchangeable strings. Each requires provider documentation. Authentication may use WebSocket headers. Network intermediaries may also affect connection behavior.

Local launch remains a different operating model. Puppeteer starts and owns that process. Remote attachment begins with an existing browser. Browser termination policy may belong elsewhere.

Legba documents none of these Puppeteer connection inputs. Its view_url supports human browser access. Do not convert that link into browserWSEndpoint. Use Legba's documented browser actions instead.

An attachment matrix for Puppeteer remote browsers.
FactorConnection inputBest fitRequired proofMain tradeoff
browserWSEndpointDirect remote browser attachment.A documented debugging WebSocket URL.Any required headers or credentials.Endpoint lifecycle remains provider-specific.
browserURLAlternative documented connection input.Providers publishing a browserURL value.Exact browserURL semantics and authentication.Behavior remains provider-specific.
Custom transportSpecialized connection implementations.A supported ConnectionTransport implementation.Clear ownership and error behavior.Custom code increases maintenance.
Local launchLocal runners and controlled hosts.Installed browser and runtime access.Application-owned process lifecycle.Compute remains application-managed.
REST session accessProvider lifecycle and browser viewing.Exact documented access semantics.No implied Puppeteer compatibility.Attachment may require another contract.

SourcesPuppeteer connect functionLegba published session client

Use a provider-neutral Puppeteer pattern.

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

The client attaches before creating a context. That context receives its own page. The example captures a simple screenshot. It closes context resources before disconnecting.

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 lifecycle handling. It also needs timeout and artifact policies. Those details depend on published contracts. Keep them outside generic attachment helpers.

  • Keep endpoints outside source code.
  • Use only documented connection inputs.
  • Create explicit browser contexts.
  • Close contexts before disconnecting.
  • Separate provider resource cleanup.
  • Never label this Legba-compatible.
Provider-neutral Puppeteer connection example.
import puppeteer from "puppeteer-core"

const browser = await puppeteer.connect({
  browserWSEndpoint: process.env.PUPPETEER_WS_ENDPOINT!,
})
const context = await browser.createBrowserContext()
const page = await context.newPage()

await page.goto("https://example.com")
await page.screenshot({ path: "page.png" })
await context.close()
await browser.disconnect()

SourcesPuppeteer connect functionPuppeteer ConnectOptionsPuppeteer installation guidePuppeteer Browser disconnect methodPuppeteer screenshots

Use contexts for explicit state boundaries.

Puppeteer browser contexts isolate browser storage. Separate contexts hold separate cookies. They also isolate local storage. Multiple contexts can share one browser process.

The default browser context has special behavior. It cannot be closed. Explicit contexts create clearer task ownership. Close each one after its assigned work.

Remote attachment may expose existing contexts. Inspect browserContexts after connection. Never assume the browser starts empty. Provider profiles may also preserve prior state.

State persistence remains provider-specific. Ask where profile data resides. Ask how long it remains. Ask how deletion works. Test isolation across consecutive tasks.

Context choices change isolation and cleanup.
FactorContext choiceOperational benefitRequired safeguard
Explicit contextCreates an isolated storage boundary.Clarifies task ownership.Close every context explicitly.
Default contextProvides the browser's existing session.May already contain pages.Inspect state before using it.
Existing remote contextMay preserve prior browser activity.Depends on remote browser ownership.Avoid assuming fresh storage.
Provider profileMay persist state across resources.Depends entirely on provider contracts.Verify retention and deletion behavior.

SourcesLegba published session client

Plan screenshots and artifacts intentionally.

Remote failures need visible evidence. A stack trace may miss page state. Screenshots capture a specific rendered moment. Puppeteer supports page and element screenshots.

The page screenshot method writes files or returns bytes. Screenshot options control output details. The calling application still owns storage. Provider filesystems may not persist afterward.

Screenshots can contain sensitive information. Login pages may expose identifiers. Account pages may expose personal data. Restrict retention and access appropriately.

Screenshots are only one diagnostic layer. Capture application logs and navigation errors. Record resource identifiers and timestamps. Test retrieval after an interrupted client.

  1. 01

    Choose required visual evidence.

    Define screenshot moments and output formats. Avoid excessive collection.

  2. 02

    Capture around failure boundaries.

    Record before risky steps. Capture again after failures.

  3. 03

    Persist evidence deliberately.

    Move outputs into approved storage. Verify retrieval after disconnection.

  4. 04

    Protect sensitive page content.

    Restrict access and retention. Delete artifacts when obligations end.

SourcesPuppeteer screenshotsPuppeteer Page screenshot methodPuppeteer browser management

Disconnect and close mean different things.

Puppeteer's disconnect method detaches the client. It does not shut down the browser. Existing pages remain open. Another client can reconnect afterward.

The browser close method closes all pages. It also closes the browser. That behavior differs from disconnect. Provider infrastructure may have another lifecycle. Confirm its termination contract separately.

Context closure provides narrower cleanup. It closes pages inside that context. Use context ownership for each task. Then choose disconnect or close deliberately.

Network failure can mimic an unplanned disconnect. Reconcile resources after client crashes. Use provider identifiers for lifecycle cleanup. Confirm termination through documented provider status.

Puppeteer cleanup actions affect different resources.
FactorActionWhat changesWhat may remain
Context closeCloses pages inside that context.Other contexts may continue.The browser process remains.
Browser disconnectDetaches the Puppeteer client.Browser and pages remain open.Provider resources may continue.
Browser closeCloses browser pages and process.Client attachment also ends.Provider records may still exist.
Provider terminationReleases provider-managed infrastructure.Uses the provider lifecycle contract.Application artifacts may remain separately.

SourcesLegba published session client

Prove the attachment contract before migration.

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

Write attachment requirements before choosing providers. Name the accepted connection input. Name required Chromium features. Name acceptable network and timeout behavior.

Legba publishes its own browser action contract. It lacks remote Puppeteer and CDP endpoints. Use its documented actions for hosted sessions. Require explicit attachment documentation before moving Puppeteer code.

Return after published compatibility appears. Then test the exact documented endpoint. Exercise disconnect and provider termination separately. Recheck documentation before upgrades. Never publish guessed endpoints.

  1. 01

    Define the attachment input.

    Choose WebSocket, browser URL, or transport. Record required behavior.

  2. 02

    Require published provider evidence.

    Verify endpoint discovery, authentication, and ownership. Record remaining unknowns.

  3. 03

    Run one representative task.

    Exercise contexts, screenshots, downloads, and errors. Preserve useful evidence.

  4. 04

    Interrupt every lifecycle layer.

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

  5. 05

    Review the published contract.

    Recheck canonical Legba documentation. Wait for explicit Puppeteer compatibility.

SourcesLegba published skill and session contractPuppeteer connect functionPuppeteer ConnectOptionsLegba published session client

FAQs.

How does Puppeteer connect remotely?
Puppeteer's connect method accepts ConnectOptions. browserWSEndpoint commonly identifies the running browser. Providers must document exact connection details.
What is browserWSEndpoint?
It identifies a browser debugging WebSocket. The browser wsEndpoint method returns it. Puppeteer's connect method can consume it.
Does Puppeteer disconnect close browsers?
No, disconnect only detaches the client. The browser keeps running. Existing pages stay open.
Does Legba support Puppeteer today?
The cited docs make no Puppeteer compatibility claim. They document no Puppeteer WebSocket. Do not infer support.
Does Legba expose CDP today?
The source publishes no CDP endpoint. Its view_url supports human browser access. Wait for explicit remote attachment documentation.
Should remote tasks use browser contexts?
Explicit contexts clarify state ownership. They isolate cookies and local storage. Close them after each task.
Who terminates provider resources?
The provider lifecycle contract controls infrastructure. Puppeteer disconnection cannot replace that contract. Verify termination separately.

References

  1. 01
  2. 02
    Puppeteer ConnectOptionsGoogle Puppeteer
  3. 03
  4. 04
  5. 05
  6. 06
  7. 07
  8. 08
  9. 09
  10. 10
    Puppeteer screenshotsGoogle Puppeteer
  11. 11
  12. 12
  13. 13

Keep exploring