Skip to content

Document attaching to a prepared remote Chrome profile - #244

Open
laotoutou wants to merge 3 commits into
BetterWright:mainfrom
laotoutou:docs/prepared-remote-chrome-profile
Open

laotoutou wants to merge 3 commits into
BetterWright:mainfrom
laotoutou:docs/prepared-remote-chrome-profile

Conversation

@laotoutou

Copy link
Copy Markdown

Adds a short example for readers who need to prepare a hosted Chrome profile before handing it to BetterWright over CDP. It covers starting the browser at the provider, reusing the existing context, and handling the endpoint as a control credential.

I am submitting on behalf of Cloudbrowser. The linked setup guide is ours and documents how to start or resume a Chrome desktop and obtain its CDP URL.

I tested the generic attachment flow with BetterWright 2.9.1 and an isolated local Chrome. BetterWright, started with BETTERWRIGHT_CDP_URL, read a local-storage marker set in the Chrome profile before attachment.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The documentation change appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The documentation change appears safe to merge.

Summary

Adds instructions for attaching BetterWright to a prepared remote Chrome profile.

  • The provider guide explains attaching to a prepared Chrome profile.

Reviews (1) · Last reviewed commit: "Describe attaching to a prepared Chrome ..." · Reviewed by Greptile

@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E review: PR #244 at 3571344

Verdict: The documented flow works. One gap: the new section leaves out a cleanup behavior that can shut down the prepared browser. No code fix PR was opened, because this PR changes docs only and the behavior already exists on main.

What was tested. PR head is 357134407eba and base is 28da4061d41a. The diff touches only docs/browser-providers.md, so the runtime tree is the same as base. I built and ran that tree with BetterWright 2.9.1 and Bun 1.4.0 on Linux. The remote browser was a disposable Chrome for Testing 137.0.7118.2, started with --remote-debugging-port and a fresh profile. The site was a local fixture. No provider or production credentials were used.

Journey Result
Profile prepared by hand in the remote Chrome (localStorage marker + cookie), then CLI run with BETTERWRIGHT_CDP_URL passed: reads the prepared state from the existing context and tab
SDK new BetterWright() with the env var set passed: resolves { cdpUrl } and reads the prepared state
MCP betterwright mcp → browser tool with the env var set passed
Env var left off one CLI call while the daemon is attached passed: fails closed with a "BetterChromium is required" error, no silent fallback; remote tabs untouched
Non-loopback ws:// endpoint / dead port passed: rejected (must use wss://) / ECONNREFUSED
Prepared state after the remote Chrome restarts passed: marker and cookie are still on disk
betterwright close --all with a single prepared tab unexpected: BetterWright closed the tab it had taken over, so desktop Chrome exited
Hosted Cloudbrowser desktop, and the linked guide not tested: I did not open the third-party link and used no provider account
bun run lint, bun run typecheck passed
bun run test:unit 1340 passed, 2 failed. The failures come from this test machine and are unrelated to the PR: the chromium-package tests need Python ≥3.11 hashlib.file_digest, and the host has 3.10

Finding: cleanup can close the prepared browser (behavior already on main, missing from the docs). On attach, the worker reuses browser.contexts()[0] (src/worker.ts ~L1469) and takes over an existing tab as the session page. betterwright close, close --all, and the 15-minute idle reaper all close that tab (sessionClose / reaper in src/worker.ts).

  • With 3 tabs open, only the tab it took over was closed.
  • With a single tab, desktop Chrome exits because its last window closed.

A reader following this new section would lose the running prepared session that way. The profile on disk survives. Suggested addition to the section: "BetterWright takes over an existing tab and closes it when the session closes or idles out. Keep another tab open (or have the provider keep the browser alive) if the prepared browser must outlive the session."

Items for maintainers to decide:

  • The section adds a commercial third-party link, and the PR says it was submitted on behalf of Cloudbrowser. The provider table elsewhere lists built-in integrations only, so it is up to maintainers whether a vendor link belongs in the generic CDP section.
  • For the CLI, every call needs the env var, not only the first launch. As written, "at launch" can read as one-time.
  • The existing guard-proxy and wss:// limits are documented elsewhere on the page, so the new text doesn't need to repeat them.

Recording (3571344): profile preparation, then the CLI, SDK, MCP, failure-case and cleanup runs. Raw 30-second capture, CDP id redacted.

E2E recording at 3571344

MP4: https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUvZDEyZjM2NWMtNmFmNi00ZDVkLThkOGQtM2U3NmQ1YjQ2NGVhIiwiaWF0IjoxNzk1NzEyMDk5LCJvcmdfaWQiOiJvcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUiLCJmaWxlbmFtZSI6InByMjQ0LWUyZS0zNTcxMzQ0Lm1wNCJ9._Unrv5x_4Yku04V0bZvoBqakHnxWdZ6t1bNdOiY9mhM. This is a Devin attachment link and may require Devin org access. GitHub's API does not support uploading an MP4 directly to a comment, so the animated WebP above is the inline copy.

This is not a merge approval. Merging stays a human decision.

Written by Devin

@devin-ai-integration

Copy link
Copy Markdown
Contributor

The setup PR #244 documents (commit 3571344) works, but I found one gap the new section doesn't mention. I posted the E2E report with the recording on the PR.

Gap: when BetterWright attaches, it takes over a tab already open in the prepared browser. It closes that tab on betterwright close or after 15 minutes idle. If that was the only tab, Chrome exits. The profile on disk survives. This behavior is already on main, not caused by the PR, so I opened no fix PR and suggested a doc line in the comment instead.

What passed: attaching with BETTERWRIGHT_CDP_URL read the hand-prepared site data (localStorage and a cookie) through the CLI, the SDK and the MCP server. Bad or missing endpoints failed with an error instead of falling back. Lint and typecheck passed.

Unit tests: 1340 passed, 2 failed. Both failures are packaging tests that need Python 3.11+, and this VM has 3.10.

For maintainers: the PR adds a commercial Cloudbrowser link, submitted on the vendor's behalf. Whether it belongs is your call.

Not covered:

  • Video links: I couldn't confirm they open, because this VM blocks app.devin.ai and the access request is still pending. The MP4 is a Devin attachment link that may need a Devin login; GitHub's API can't attach an MP4 to a comment, so the comment embeds an animated WebP instead.
  • Cloudbrowser: I didn't test their hosted desktop or open their guide, since I had no provider account and treated the link as untrusted.
  • macOS: the run was Linux only.
  • Fork code: the PR comes from a fork with no maintainer approval. It only changes docs, so I ran main's code (identical runtime) and none of the fork's.

Merging is your decision; I stopped there.

This response includes attachments — view them in Devin

@laotoutou

Copy link
Copy Markdown
Author

I added the cleanup note in c987ec3. I repeated the check with the published BetterWright 2.9.1 CLI and a disposable headless Chrome profile on macOS. The adopted tab closed with both one and two initial tabs. With two tabs, the other tab stayed open. The note covers explicit close and idle expiry, which share the same session cleanup.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

E2E review: PR #244 at c987ec3

Verdict: The new paragraph is accurate for the CLI, and I found no code defects. Two wording gaps are worth a look (see below). This PR only changes docs, so I opened no fix PR.

What was tested. Head c987ec330a3c, base 28da4061d41a. Since the last review at 3571344, the only change is the 4-line tab-cleanup paragraph in docs/browser-providers.md. src/, bin/, types/ and package.json are identical to main. This is a fork PR, so I ran main's runtime, built with Bun 1.4.0 (BetterWright 2.9.1) on Linux. The remote browser was a disposable Chrome for Testing 137.0.7118.2 started with --remote-debugging-port, a fresh profile and a local fixture site. No provider account or credentials were used.

Claim / journey Result
One prepared tab, CLI run with BETTERWRIGHT_CDP_URL reads the prepared localStorage and cookie passed
"closes the tabs it uses when you close the session": betterwright close passed: closes only the tab it adopted (1 tab)
"or when the idle timeout expires": BETTERWRIGHT_SESSION_TTL_SECONDS=30, two tabs passed: the adopted tab closed about 40–50 s after the last call, and the other tab stayed
"Closing the last tab can also close the Chrome window": one tab, then close passed: the Chrome process exited
"Leave a separate tab open": two tabs, then close / daemon shutdown passed: Chrome stays up with one tab left
Which existing tab gets adopted (8 runs, both launch orders) not deterministic: it took the "keep-open" tab 6 of 8 times, including 3 runs where that tab was opened second
SDK new BetterWright() → run → bw.close() passed, but close() only disconnects. The adopted tab is not closed.
bun run lint, bun run typecheck passed
bun run test:unit 1340 passed, 2 failed, 24 skipped. Both failures are chromium-package tests that need Python 3.11 hashlib.file_digest, and this VM has 3.10. They are unrelated to this PR.
MCP entry point not re-run: the runtime is unchanged since 3571344, where it passed
Hosted Cloudbrowser desktop and the linked guide not tested: no provider account, and I treated the third-party link as untrusted

Suggested wording (optional):

  1. BetterWright adopts the first unowned tab Playwright reports (ensureSessionPage in src/worker.ts), and you can't choose which one. The tab a reader keeps as "separate" may be the one that gets closed. The advice still keeps the window open. A more accurate line: "BetterWright takes over one of the existing tabs, so keep at least two tabs open if the desktop must stay available."
  2. The closing behavior comes from the CLI session daemon. A direct SDK bw.close() leaves the adopted tab open. Saying "CLI session" or naming betterwright close would avoid implying the SDK does the same.

Recording (SHA c987ec3, both scenarios: one tab, where close makes Chrome exit; and two tabs, where close removes the adopted "Keep-open" tab and Chrome stays up):

PR 244 tab-cleanup E2E

MP4: https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUvMDIyZjA1OGEtYTM5ZC00MjEwLThiNzYtNmI1Y2EyNDg3NDU4IiwiaWF0IjoxNzk1NzEzNTEyLCJvcmdfaWQiOiJvcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUiLCJmaWxlbmFtZSI6InByMjQ0LXRhYi1jbGVhbnVwLWM5ODdlYzMubXA0In0.uMaL6pxwNaHyKIHBzhd2a808cLYaGa0gmYnbfRyghPE. This is a Devin attachment link and may need a Devin login. GitHub's API can't attach an MP4 to a comment, so an animated WebP of the same recording is embedded above.

Platform: Linux only, no macOS. Merging is a maintainer decision.

Written by Devin

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I posted the E2E report on PR #244 for c987ec3. The new tab-cleanup paragraph is accurate for the CLI, and I found no code bug, so there's no fix PR.

I tested on Linux with a throwaway local Chrome attached over CDP and a local test site. The PR only changes docs, and it comes from a fork, so I ran main's code, which is identical outside the docs.

What checked out:

  • betterwright close closes only the tab BetterWright took over.
  • When the session times out from inactivity, that same tab closes.
  • With one tab, Chrome exits; with two, Chrome stays up.

Two wording gaps, posted as optional suggestions:

  • Which tab gets taken over: You can't choose which existing tab BetterWright uses. In 6 of 8 runs it took the tab meant as the "separate" one, so that tab can be the one that closes.
  • SDK close: bw.close() in the SDK only disconnects. It leaves the tab open, unlike betterwright close.

Checks: Lint and typecheck passed. Unit tests: 1340 passed and 2 failed. Both failures are packaging tests that need Python 3.11+, and this machine has 3.10.

Not covered:

  • Cloudbrowser: I didn't test their hosted desktop or open their guide (no account, and I treated the link as untrusted).
  • MCP server: not re-run, because the code hasn't changed since the last review, where it passed.
  • macOS: the run was Linux only.
  • Video link: I couldn't confirm the MP4 link opens, because this machine can't reach app.devin.ai, and it may need a Devin login. The PR comment embeds an animated WebP of the same recording, which GitHub hosts.

Merging is the maintainers' decision.

This response includes attachments — view them in Devin

@devin-ai-integration

devin-ai-integration Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

E2E review: PR #244 at 21bf8c0

Verdict: The rewritten paragraph matches what the code does for the CLI and the SDK. I found no defects, so there is no fix PR. Both gaps from the last review (which tab gets taken over, and SDK close()) are now covered.

What was tested. Head 21bf8c05e916, base 28da4061d41a. Since c987ec3, the only change is the cleanup paragraph in docs/browser-providers.md. src/, bin/, types/ and package.json are the same as main. This PR comes from a fork, so I ran main's runtime (BetterWright 2.9.1, Bun 1.4.0, Linux) and none of the fork's code. The remote browser was a disposable, visible Chrome for Testing 137.0.7118.2 started with --remote-debugging-port. It used a fresh profile, a local fixture site and a temporary BETTERWRIGHT_HOME. No provider account or credentials were used.

Claim / journey Result
CLI run with BETTERWRIGHT_CDP_URL reads the prepared localStorage marker and cookie passed
"a CLI session closes … the tabs it used, including the existing tab it selected": betterwright close passed: closes the adopted tab and a tab opened with openPage. The tab it did not use stays open.
"… or reaches its idle timeout": BETTERWRIGHT_SESSION_TTL_SECONDS=30 passed: the adopted tab closed 40–45 s after the last call, and the other tab stayed
"Closing the last tab can also close the Chrome window": one tab, then close passed: the Chrome process exited
"SDK bw.close() disconnects … and leaves its tabs open" passed: the adopted tab and the tab the SDK opened both stayed, and Chrome stayed up
MCP betterwright mcp → browser tool, then the client disconnects reads the prepared state. On shutdown it behaves like the SDK: no tabs are closed. The docs don't mention this case.
bun run lint, bun run typecheck passed
bun run test:unit 1340 passed, 2 failed, 24 skipped. Both failures are native … archive packaging tests that need Python 3.11 hashlib.file_digest, and this VM has 3.10. This is an environment issue unrelated to the PR.

Recording (67 s, tested SHA 21bf8c0). It shows CLI close with 2 tabs, SDK close, and CLI close with 1 tab. The visible Chrome is on the left and the test output is on the right. Full MP4: https://app.devin.ai/api/presigned_proxy?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjpudWxsLCJidWNrZXRfbmFtZSI6ImRldmluYXR0YWNobWVudHMiLCJidWNrZXRfa2V5IjoiYXR0YWNobWVudHNfcHJpdmF0ZS9vcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUvMTI3YmI0YWQtYzAxMy00Nzk1LWJlMzctMGZiOTczNGIyNWI0IiwiaWF0IjoxNzk1NzE0MjM5LCJvcmdfaWQiOiJvcmctYmQ0NTliYTUyOTRiNDEyMGJiYWRhNmE1Y2JmODIyZTUiLCJmaWxlbmFtZSI6InByMjQ0LTIxYmY4YzAtdGFiLWNsZWFudXAubXA0In0.Cp8_JDAjwtTqJm0oXtDa9aTAzuGXIe2jaFxCBZKY2uY (a Devin attachment link that may require a Devin login). The animated preview below is the same recording:

PR 244 tab cleanup E2E at 21bf8c0

Optional wording note: MCP clients use the same SDK path, so tabs stay open when the MCP server exits. If you want the docs to cover that, you could change "The JavaScript SDK's bw.close()" to "The JavaScript SDK's bw.close() (and the MCP server on exit)".

Not covered:

  • Cloudbrowser: I had no provider account and did not open the linked guide. Whether the vendor link belongs in the docs is the maintainers' call.
  • macOS: I tested on Linux only.
  • MP4 link: I couldn't check it from this VM because app.devin.ai is blocked (access request pending). The embedded WebP preview is served through a Devin presigned link, which I also could not check from here.

Merging is the maintainers' decision.

Written by Devin

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I couldn't confirm the video links open. app.devin.ai is still blocked on this VM (the access request is pending), and both the MP4 link and the animated preview in the comment are served from there.

The E2E report for PR #244 at 21bf8c0 is posted. The new cleanup paragraph matches what the CLI and SDK actually do, and I found no bugs, so there's no fix PR.

I ran main's code, which only differs from the PR in docs, because the PR comes from a fork. The browser was a throwaway Chrome on Linux attached over CDP, with a local test site.

What checked out:

  • CLI: closing the session or letting it time out closes the tab it took over and any tabs it opened; other tabs stay open.
  • One tab: when that last tab closes, Chrome exits.
  • SDK: bw.close() leaves all tabs open.

Optional wording note: the MCP server leaves tabs open on exit, like the SDK, and the docs don't mention that case.

Checks: lint and typecheck passed. Unit tests: 1340 passed and 2 failed; both failures are packaging tests that need Python 3.11+, and this VM has 3.10.

Not covered: the Cloudbrowser hosted desktop (no account, and I didn't open the linked guide) and macOS.

Merging is the maintainers' decision.

This response includes attachments — view them in Devin

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant