Repository navigation
feat: persistent CDP sessions per target and mm cdp --target sw - #90
Merged
cryptotavares merged 12 commits intoNov 18, 2026
Merged
cryptotavares merged 12 commits into
cryptotavares merged 12 commits into
Conversation
…mmcli-p2-01-browser-cdp # Conflicts: # CHANGELOG.md
…mmcli-p2-01-browser-cdp # Conflicts: # README.md
…mmcli-p2-01-browser-cdp
…ts' into cryptotavares/mmcli-p2-01-browser-cdp # Conflicts: # README.md # SKILL.md # src/platform/playwright-driver.ts
The changelog is generated when a release is created.
…ts' into cryptotavares/mmcli-p2-01-browser-cdp
cryptotavares
marked this pull request as ready for review
November 16, 2026 18:15
seaona
previously approved these changes
Nov 18, 2026
seaona
left a comment
Member
There was a problem hiding this comment.
Changes look good, just found one caveat: any command that changes how the page behaves now stays in effect until cleanup. Ie:
- Fetch.enable pauses every request with nobody to continue it.
- Debugger.pause freezes all Playwright interaction.
- Emulation.* overrides and Network.setBlockedURLs stay applied.
Before this PR, detaching the session undid all of these. There's no reset path short of mm cleanup or knowing the matching disable call
Suggestion (can be follow-up): add some guard rail, ie, a line in SKILL telling agents to undo what they change (or use --fresh)
…ts' into cryptotavares/mmcli-p2-01-browser-cdp # Conflicts: # README.md # src/cli/mm.ts # src/tools/utils/discovery.ts
seaona
approved these changes
Nov 18, 2026
This was referenced Nov 18, 2026
cryptotavares
added a commit
that referenced
this pull request
Nov 18, 2026
…nection (#91) ## Description `mm launch --platform ios|android --metro-port 8085` stored the port, but `mm cdp` and `mm hermes-targets` resolved it again for each call and fell back to `HERMES_METRO_PORT` or 8081 (baseline B5). On a machine with a second Metro on 8081 they reached the wrong app; without one they failed. Every Hermes call also opened its own WebSocket. - `MobilePlatformDriver` options gain `metroPort`, `deviceId` and `appId`. New optional `IPlatformDriver.setHermesDefaults()`: the launch tool applies `--metro-port` / `--device-id` to the driver after a successful mobile launch, so B5 is fixed with no consumer change. - Precedence for each call: per-call `--metro-port` / `--app-id`, then the driver (launch) value, then `HERMES_METRO_PORT` / `HERMES_APP_ID`, then 8081 / the platform default. CDP failures name the port they tried. - When the loaded device-mcp exports `HermesClient` (MetaMask/device-mcp#54), `cdp` keeps one persistent client per session target. A per-call port or app id that differs uses a one-shot call, so the persistent client is never retargeted. The client is closed on `dispose()`. With device-mcp 0.7.0 (no `HermesClient`), core keeps the one-shot `runHermesCdp` path (feature-detected). - `hermes-targets` also reports `sessionMetroPort`, `pinnedDeviceId`, `connected` and `deviceId` (additive). Part of the mm CLI v2 effort: ticket `P2-03` (Tier 2). Stacked on #90 (review that first). Depends on MetaMask/device-mcp#54: the persistent connection needs a device-mcp release with `HermesClient`, then a dependency bump here. The B5 fix works with the released 0.7.0. ## Breaking changes None. New options and output fields only. ## Consumer impact | Consumer | Change needed | |---|---| | Mobile `tests/llm-workflow/` | Optional: pass `{ metroPort, deviceId, appId }` when constructing `MobilePlatformDriver` (patch ready). Core already applies the launch values itself. | ## Proof Yalc build in Mobile (dev client 8.19.0, iOS sim + Android emulator, Metro 8085, launched with `--metro-port 8085`), `mm cdp Runtime.evaluate 1+1` without `--metro-port`, 10 runs: | Check | Before (#79 stack) | After | |---|---|---| | Android, 10 calls | 0/10: `hermes-targets` says `metroPort: 8081, metroDown: true` | **10/10**, `sessionMetroPort: 8085`, p50 15–40 ms | | iOS, 10 calls | — | **10/10**, p50 2 ms | | `hermes-targets` after a call | — | `connected: true`, `pinnedDeviceId` set, `deviceId` = launch device | The before build reached Metro only with an explicit `--metro-port 8085` (90 ms per call on Android). The raw client bench is in MetaMask/device-mcp#54 (Android p50 165 → 5 ms). <details> <summary>Unit tests</summary> ``` Test Files 58 passed (58) Tests 2178 passed (2178) (with #89 and #90 merged) All files | 97.94 | 95.5 | 97.59 | 98.04 | ``` Covers the precedence table, launch applies the port, one client for two calls, one-shot on a per-call override, fallback without `HermesClient`, close on dispose, the pin persisting, and the new `hermes-targets` fields. `CI=1` thresholds not lowered; `tsc -p tsconfig.build.json` and `yarn lint` clean. </details>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
withCdpSession(src/tools/utils/cdp.ts) opens and detaches a CDP session for every call, so domains and listeners enabled withmm cdp(Runtime.addBinding,Network.enable) die with it. The Extension background service worker, where the wallet state lives, cannot be reached at all.CdpManager(src/platform/cdp-manager.ts), one perBrowserContext: it opens one CDP session per target the first time it is needed and reuses it. Concurrent callers share one open; a dead session is opened again on the next call; a closed page drops its session;dispose()on cleanup detaches everything.mm cdp --target swreaches the Extension service worker. Playwright cannot open a CDP session on aWorker, so the manager attaches from the browser CDP session (Target.attachToTarget, not flattened) and keys the session on the CDP target id. A restarted worker (new target id) gets a new session.--targetispage|sw|hermes|android-webview. The default is the active page on the browser andhermeson mobile; each platform rejects the other's targets withMM_INVALID_INPUT. Newmm cdp --freshkeeps today's one-shot session.withCdpSession, because it enables and disablesAccessibility.Part of the mm CLI v2 effort: ticket
P2-01(Tier 2).Stacked on #89 (review that first).
Breaking changes
None. The default target and the result shape are unchanged.
Consumer impact
None.
Proof
Yalc build of this branch in the Extension (headless e2e build),
proof/p2-01/ext.sh:Runtime.addBindingon the page, then a later call sees it (also after a--freshcall)typeofbinding =functionmm cdp Runtime.evaluate 'typeof globalThis.stateHooks' --target swobject; the default target is still the Extension pageServiceWorker.stopAllWorkers) →--target swcall--target swstateHooksis there)Unit tests
cdp-manager.ts100% statements, branches, functions and lines.CI=1thresholds not lowered;tsc -p tsconfig.build.json,yarn lintand prettier clean.