Skip to content

feat(browser): add headless existing-session MCP support esp for Linux/Docker/VPS - #45769

Merged
vincentkoc merged 9 commits into
mainfrom
vincentkoc-code/browser-headless-default-profile-fallback
Mar 14, 2026
Merged

vincentkoc merged 9 commits into
mainfrom
vincentkoc-code/browser-headless-default-profile-fallback

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Mar 14, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Problem: OpenClaw's existing-session browser driver was hardwired to Chrome DevTools MCP --autoConnect, which requires a live desktop Chrome session and user approval.
  • Why it matters: Linux/VPS deployments could not use MCP-backed browser control, even though upstream chrome-devtools-mcp supports headless launch plus --browserUrl / --wsEndpoint attach.
  • What changed: existing-session now supports three MCP modes: desktop --autoConnect, headless MCP-managed Chrome launch, and explicit MCP attach to browserUrl / wsEndpoint via profile cdpUrl.
  • What did NOT change (scope boundary): the extension relay is still desktop/interactive; existing-session still does not have full feature parity for every browser action route.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • Related #

User-visible / Behavior Changes

  • driver="existing-session" can now work on Linux/VPS in headless mode.
  • In headless mode, existing-session no longer falls back away from MCP; only extension-relay defaults are redirected to openclaw.
  • browser.profiles.<name>.cdpUrl is now accepted for existing-session profiles and is interpreted as an MCP browserUrl or wsEndpoint target.
  • Docs now describe both desktop auto-connect and headless/Linux MCP flows.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) Yes
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:
    • Existing-session can now launch Chrome through MCP in headless environments or attach MCP to explicit browser URLs. This is still the same browser tool trust boundary; mitigation is explicit profile selection, existing browser config, and keeping headless server profiles isolated from personal browser state.

Repro + Verification

Environment

  • OS: macOS host for development; implementation targets Linux/VPS/headless MCP paths
  • Runtime/container: Node 22 workspace
  • Model/provider: N/A
  • Integration/channel (if any): browser tool / browser control server / Chrome DevTools MCP
  • Relevant config (redacted): browser.headless=true, browser.noSandbox=true, optional existing-session cdpUrl

Steps

  1. Configure an existing-session profile and enable browser.headless=true.
  2. Either omit profile cdpUrl to let MCP launch headless Chrome, or set browser.profiles.<name>.cdpUrl to http://127.0.0.1:9222 or a devtools browser WS endpoint.
  3. Start/status/tabs against that profile.

Expected

  • Existing-session uses MCP in headless mode instead of requiring desktop --autoConnect.
  • HTTP target URLs map to MCP --browserUrl and WS targets map to --wsEndpoint.

Actual

  • Before this change, existing-session always used --autoConnect and therefore required a local interactive Chrome session.

Evidence

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: focused Vitest coverage for headless MCP launch plans, browserUrl/wsEndpoint attach plans, existing-session profile resolution, profile creation, and headless default-profile routing.
  • Edge cases checked: extension-relay still falls back away from headless implicit default, existing-session no longer does; loopback MCP targets; desktop autoConnect behavior remains available.
  • What you did not verify: full repo pnpm check is still blocked by pre-existing unrelated TypeScript errors in src/browser/pw-ai.ts and src/browser/routes/agent.act.ts.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly: keep using profile="openclaw" or revert this PR.
  • Files/config to restore: src/browser/chrome-mcp.ts, src/browser/config.ts, src/browser/profiles-service.ts
  • Known bad symptoms reviewers should watch for: headless existing-session profiles unexpectedly trying desktop --autoConnect, or MCP target URLs not mapping to browserUrl/wsEndpoint.

Risks and Mitigations

  • Risk: existing-session semantics are broader now, since they can launch headless Chrome via MCP as well as attach to a running browser URL.
    • Mitigation: desktop autoConnect behavior remains the default when not headless and no explicit target URL is configured; docs/help were updated to make the distinction explicit.
  • Risk: reviewers may assume existing-session now has total feature parity with the managed browser.
    • Mitigation: PR scope and docs explicitly call out that some action routes still remain unsupported for existing-session.

@vincentkoc vincentkoc self-assigned this Mar 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR docs Improvements or additions to documentation size: M and removed size: S labels Mar 14, 2026
@vincentkoc vincentkoc changed the title fix(browser): prefer managed default profile in headless mode feat(browser): add headless existing-session MCP support Mar 14, 2026
@vincentkoc
vincentkoc marked this pull request as ready for review March 14, 2026 08:30
@greptile-apps

greptile-apps Bot commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extends the existing-session browser driver to support three Chrome DevTools MCP launch modes — desktop --autoConnect, headless MCP-managed Chrome launch, and explicit --browserUrl/--wsEndpoint attach — enabling Linux/VPS deployments that previously required an interactive desktop Chrome session. The implementation adds a buildChromeMcpLaunchPlan function in chrome-mcp.ts, surfaces an optional mcpTargetUrl field on resolved existing-session profiles, replaces the previous hard rejection of cdpUrl on existing-session profiles with MCP-target storage, and introduces a headless-aware implicit profile fallback so extension-relay defaults are transparently redirected to the managed openclaw profile.

  • The core logic change (buildChromeMcpLaunchPlan) is clean and well-tested; all three mode branches have focused Vitest coverage.
  • resolveImplicitProfileName correctly limits the relay-to-openclaw fallback to implicit (no-profile-argument) requests only, leaving explicit profile selections unchanged.
  • Two minor naming inconsistencies are worth addressing: mode: "browserUrl" is returned for both --browserUrl and --wsEndpoint invocations, and mode: "local-existing-session" in BrowserProfileCapabilities now contradicts isRemote: true for non-loopback targets. Neither causes incorrect runtime behaviour today, but both could mislead future contributors branching on these fields.
  • The buildChromeMcpLaunchPlanForTest export exposes an internal function from the production module; this is a pragmatic but common pattern in the codebase.

Confidence Score: 4/5

  • Safe to merge; no logic bugs found, backward-compatible, and well-covered by focused tests.
  • The implementation is clean, fully backward-compatible, and the critical code paths (launch plan selection, config resolution, profile creation, headless default fallback) each have dedicated test coverage. The two deductions are for minor naming inconsistencies (mode: "browserUrl" for both HTTP and WS targets; mode: "local-existing-session" when isRemote is true) that don't affect correctness but could mislead future contributors.
  • src/browser/chrome-mcp.ts and src/browser/profile-capabilities.ts deserve a second look for the mode naming inconsistencies noted in inline comments.

Comments Outside Diff (1)

  1. src/browser/profile-capabilities.ts, line 41-53 (link)

    mode: "local-existing-session" is a misnomer when isRemote is true

    Before this PR, existing-session was always a desktop-local flow, so hard-coding "local-existing-session" was accurate. Now that cdpUrl on an existing-session profile can point to a non-loopback host, isRemote may be true while mode still reads "local-existing-session". These two fields now contradict each other.

    If any downstream code (e.g. diagnostics, logging, UI labels) ever switches on mode to infer locality, it will silently give the wrong answer for remote existing-session profiles. Consider either renaming the mode to something driver-centric (e.g. "chrome-mcp") or documenting clearly that mode describes the driver, not the network topology, so that isRemote is the authoritative locality flag.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/browser/profile-capabilities.ts
    Line: 41-53
    
    Comment:
    **`mode: "local-existing-session"` is a misnomer when `isRemote` is true**
    
    Before this PR, existing-session was always a desktop-local flow, so hard-coding `"local-existing-session"` was accurate. Now that `cdpUrl` on an existing-session profile can point to a non-loopback host, `isRemote` may be `true` while `mode` still reads `"local-existing-session"`. These two fields now contradict each other.
    
    If any downstream code (e.g. diagnostics, logging, UI labels) ever switches on `mode` to infer locality, it will silently give the wrong answer for remote existing-session profiles. Consider either renaming the mode to something driver-centric (e.g. `"chrome-mcp"`) or documenting clearly that `mode` describes the driver, not the network topology, so that `isRemote` is the authoritative locality flag.
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/browser/chrome-mcp.ts
Line: 47-69

Comment:
**`mode: "browserUrl"` conflates HTTP and WS targets**

When a profile's `mcpTargetUrl` starts with `ws:` or `wss:`, the function pushes `--wsEndpoint` but still returns `mode: "browserUrl"`. The two cases use different MCP CLI flags, yet they share the same mode discriminant. Any future code (or external caller) that branches on `mode` would have no way to distinguish between `--browserUrl` and `--wsEndpoint` without inspecting the `args` array directly.

Consider introducing a third mode value (e.g. `"wsEndpoint"`) or renaming the shared value to something neutral like `"attach"`:

```typescript
type ChromeMcpLaunchPlan = {
  args: string[];
  mode: "autoConnect" | "attach" | "headless";
};
```

This also makes the test at `chrome-mcp.test.ts:157` ("uses wsEndpoint…") more intuitive, since the assertion `expect(plan.mode).toBe("browserUrl")` is currently surprising when reading the WS test case.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/browser/profile-capabilities.ts
Line: 41-53

Comment:
**`mode: "local-existing-session"` is a misnomer when `isRemote` is true**

Before this PR, existing-session was always a desktop-local flow, so hard-coding `"local-existing-session"` was accurate. Now that `cdpUrl` on an existing-session profile can point to a non-loopback host, `isRemote` may be `true` while `mode` still reads `"local-existing-session"`. These two fields now contradict each other.

If any downstream code (e.g. diagnostics, logging, UI labels) ever switches on `mode` to infer locality, it will silently give the wrong answer for remote existing-session profiles. Consider either renaming the mode to something driver-centric (e.g. `"chrome-mcp"`) or documenting clearly that `mode` describes the driver, not the network topology, so that `isRemote` is the authoritative locality flag.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: 44da868

Comment thread src/browser/chrome-mcp.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44da868b85

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/browser/config.ts Resolved
@vincentkoc
vincentkoc force-pushed the vincentkoc-code/browser-headless-default-profile-fallback branch from 88fd668 to 60a9715 Compare March 14, 2026 21:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 60a971575e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@vincentkoc vincentkoc changed the title feat(browser): add headless existing-session MCP support feat(browser): add headless existing-session MCP support esp for Linux/Docker/VPS Mar 14, 2026
@vincentkoc
vincentkoc merged commit 173fe3c into main Mar 14, 2026
8 checks passed
romeroej2 pushed a commit to romeroej2/openclaw that referenced this pull request Mar 16, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 26, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note

(cherry picked from commit 173fe3c)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 26, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note

(cherry picked from commit 173fe3c)
sbezludny pushed a commit to sbezludny/openclaw that referenced this pull request Mar 27, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…x/Docker/VPS (openclaw#45769)

* fix(browser): prefer managed default profile in headless mode

* test(browser): cover headless default profile fallback

* feat(browser): support headless MCP profile resolution

* feat(browser): add headless and target-url Chrome MCP modes

* feat(browser): allow MCP target URLs in profile creation

* docs(browser): document headless MCP existing-session flows

* fix(browser): restore playwright browser act helpers

* fix(browser): preserve strict selector actions

* docs(changelog): add existing-session MCP note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants