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.
The cited Legba preview docs publish no Puppeteer WebSocket. They publish no CDP endpoint. Current Puppeteer compatibility remains undocumented.
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's proposed preview stops before Puppeteer attachment.
The cited Legba docs describe a proposed public-preview contract. They provide illustrative endpoint shapes. They publish no callable host or key issuer. Do not treat the examples as a live service.
The proposed docs sketch REST instance lifecycle. They show create, list, and destroy operations. These examples describe a possible contract, not currently callable endpoints.
Illustrative responses include an access_url. The proposal never defines browserWSEndpoint compatibility. It never defines any CDP endpoint.
The cited public docs establish no Puppeteer endpoint. An illustrative access_url cannot establish attachment semantics. Wait for an explicit connection contract. Recheck canonical docs before implementation.
| Factor | Documented today | Not documented today | Engineering consequence |
|---|---|---|---|
| REST lifecycle | Illustrative create, list, and destroy contract. | Puppeteer browser command transport. | Evaluate lifecycle separately from attachment. |
| Instance access | Illustrative responses include an access_url. | Access URL protocol semantics. | Never derive browserWSEndpoint values. |
| REST authentication | A bearer API-key pattern is proposed. | Browser-channel authentication requirements. | Do not reuse assumptions across channels. |
| Puppeteer compatibility | The cited docs make no compatibility claim. | WebSocket or browser URL inputs. | Keep Puppeteer integration unimplemented. |
Legba's proposed documentation supports limited conclusions.
SourcesLegba API documentationLegba Instances APILegba API quickstartLegba API authenticationPuppeteer ConnectOptions
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.
The cited Legba docs document none of these inputs. Their illustrative access_url has unspecified automation semantics. Do not convert or rewrite that field. Wait for published Puppeteer details.
| Factor | Connection input | Best fit | Required proof | Main tradeoff |
|---|---|---|---|---|
| browserWSEndpoint | Direct remote browser attachment. | A documented debugging WebSocket URL. | Any required headers or credentials. | Endpoint lifecycle remains provider-specific. |
| browserURL | Alternative documented connection input. | Providers publishing a browserURL value. | Exact browserURL semantics and authentication. | Behavior remains provider-specific. |
| Custom transport | Specialized connection implementations. | A supported ConnectionTransport implementation. | Clear ownership and error behavior. | Custom code increases maintenance. |
| Local launch | Local runners and controlled hosts. | Installed browser and runtime access. | Application-owned process lifecycle. | Compute remains application-managed. |
| REST instance access | Provider lifecycle and browser viewing. | Exact documented access semantics. | No implied Puppeteer compatibility. | Attachment may require another contract. |
An attachment matrix for Puppeteer remote browsers.
SourcesPuppeteer ConnectOptionsPuppeteer Browser wsEndpointPuppeteer browser managementLegba Instances API
SourcesPuppeteer connect function
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.
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.
| Factor | Context choice | Operational benefit | Required safeguard |
|---|---|---|---|
| Explicit context | Creates an isolated storage boundary. | Clarifies task ownership. | Close every context explicitly. |
| Default context | Provides the browser's existing session. | May already contain pages. | Inspect state before using it. |
| Existing remote context | May preserve prior browser activity. | Depends on remote browser ownership. | Avoid assuming fresh storage. |
| Provider profile | May persist state across resources. | Depends entirely on provider contracts. | Verify retention and deletion behavior. |
Context choices change isolation and cleanup.
SourcesPuppeteer browser managementPuppeteer default browser contextPuppeteer connect functionPuppeteer browser contexts methodLegba Instances API
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.
- 01
Choose required visual evidence.
Define screenshot moments and output formats. Avoid excessive collection.
- 02
Capture around failure boundaries.
Record before risky steps. Capture again after failures.
- 03
Persist evidence deliberately.
Move outputs into approved storage. Verify retrieval after disconnection.
- 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.
| Factor | Action | What changes | What may remain |
|---|---|---|---|
| Context close | Closes pages inside that context. | Other contexts may continue. | The browser process remains. |
| Browser disconnect | Detaches the Puppeteer client. | Browser and pages remain open. | Provider resources may continue. |
| Browser close | Closes browser pages and process. | Client attachment also ends. | Provider records may still exist. |
| Provider termination | Releases provider-managed infrastructure. | Uses the provider lifecycle contract. | Application artifacts may remain separately. |
Puppeteer cleanup actions affect different resources.
SourcesPuppeteer browser managementPuppeteer Browser close methodLegba Instances APILegba API errors
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.
The cited Legba lifecycle contract is a design reference only. It lacks Puppeteer endpoint details. It also lacks CDP endpoint details. Current evidence cannot justify implementation.
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.
- 01
Define the attachment input.
Choose WebSocket, browser URL, or transport. Record required behavior.
- 02
Require published provider evidence.
Verify endpoint discovery, authentication, and ownership. Record remaining unknowns.
- 03
Run one representative task.
Exercise contexts, screenshots, downloads, and errors. Preserve useful evidence.
- 04
Interrupt every lifecycle layer.
Test network loss and client failure. Reconcile provider resources afterward.
- 05
Review the current preview.
Recheck canonical Legba documentation. Wait for explicit Puppeteer compatibility.
SourcesLegba API documentationLegba API quickstartLegba Instances APIPuppeteer connect functionPuppeteer ConnectOptions
FAQs.
How does Puppeteer connect remotely?
What is browserWSEndpoint?
Does Puppeteer disconnect close browsers?
Does Legba support Puppeteer today?
Does Legba expose CDP today?
Should remote tasks use browser contexts?
Who terminates provider resources?
References
- 01
- 02Legba API quickstartLegba
- 03Legba Instances APILegba
- 04
- 05Legba API errorsLegba
- 06Puppeteer connect functionGoogle Puppeteer
- 07Puppeteer ConnectOptionsGoogle Puppeteer
- 08Puppeteer Browser wsEndpointGoogle Puppeteer
- 09Puppeteer browser managementGoogle Puppeteer
- 10Puppeteer default browser contextGoogle Puppeteer
- 11Puppeteer browser contexts methodGoogle Puppeteer
- 12Puppeteer installation guideGoogle Puppeteer
- 13Puppeteer Browser disconnect methodGoogle Puppeteer
- 14Puppeteer Browser close methodGoogle Puppeteer
- 15Puppeteer screenshotsGoogle Puppeteer
- 16Puppeteer Page screenshot methodGoogle Puppeteer