Commit fb13b5f
authored
fix: connect React Native CDP targets (#30)
## End-user impact
React Native targets exposed through Metro can now be selected by
`agent-cdp` without failing the WebSocket handshake with HTTP 401. This
unlocks the existing JS heap usage, heap snapshot, allocation, and
leak-triplet workflows for RN/Hermes targets that implement those CDP
methods.
Users can continue the normal flow:
```sh
agent-cdp target list --url http://127.0.0.1:8081
agent-cdp target select <target-id>
agent-cdp memory usage sample --gc
agent-cdp memory snapshot capture --name baseline --gc
```
## Compatibility
Chrome and Node targets keep the existing WebSocket behavior. Only React
Native target descriptors receive an `Origin` header, derived from the
discovery URL origin.
Existing commands, output formats, daemon state, snapshot artifacts, and
saved analysis workflows are unchanged. The docs now call out that React
Native/Hermes may expose only a subset of browser CDP and should use
heap usage/snapshot workflows when browser-only domains are unsupported.
## Risks
The main risk is target-specific: some non-Metro React Native-compatible
endpoints might validate Origin differently. The fallback still derives
an origin from the WebSocket URL if the discovery source URL is
malformed.
## Manual testing
Setup used during investigation:
- Expo SDK 56 test app running in Expo Go 56.0.3 on iOS simulator
- Metro on `http://127.0.0.1:8081`
Observed before this fix: `agent-cdp target select
<react-native-target>` failed with `Unexpected server response: 401`.
Validation performed:
- `pnpm --filter agent-cdp exec vitest run
src/__tests__/transport.test.ts`
- `pnpm --filter agent-cdp typecheck`
- `pnpm --filter agent-cdp format`
- `pnpm --filter agent-cdp lint`
- `pnpm --filter agent-cdp build`
- With a temporary local transport patch, `target select` succeeded
against Expo Go 56 and memory commands captured JS heap usage, heap
snapshots, snapshot diffs, leak-triplet output, retainers, and
allocation hotspots.1 parent 220dfd2 commit fb13b5f
4 files changed
Lines changed: 101 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
| 104 | + | |
| 105 | + | |
103 | 106 | | |
104 | 107 | | |
105 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
71 | 75 | | |
72 | 76 | | |
73 | 77 | | |
| |||
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
183 | 190 | | |
184 | 191 | | |
185 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
| |||
20 | 38 | | |
21 | 39 | | |
22 | 40 | | |
23 | | - | |
| 41 | + | |
24 | 42 | | |
25 | 43 | | |
26 | 44 | | |
| |||
0 commit comments