You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: server/lib/cdpmonitor/README.md
+85-1Lines changed: 85 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,4 +79,88 @@ Fields that need no mutex use `sync/atomic`: `nextID`, `mainSessionID`, `running
79
79
80
80
### WebSocket concurrency
81
81
82
-
`coder/websocket` guarantees one concurrent `Read` and one concurrent `Write` are safe on the same connection. `readLoop` is the sole reader. All writes go through `send`, which calls `conn.Write` directly -- `conn.Write` is internally serialized by the library, so no external write mutex is needed.
82
+
`coder/websocket` guarantees one concurrent `Read` and one concurrent `Write` are safe on the same connection. `readLoop` is the sole reader. All writes go through `send`, which calls `conn.Write` directly -- `conn.Write` is internally serialized by the library, so no external write mutex is needed.
83
+
84
+
## Event data model
85
+
86
+
### Envelope and top-level fields
87
+
88
+
Every event arrives as an `Envelope`:
89
+
90
+
```json
91
+
{
92
+
"capture_session_id": "cs_abc123",
93
+
"seq": 42,
94
+
"event": {
95
+
"ts": 1746123456789000,
96
+
"type": "network_request",
97
+
"category": "network",
98
+
"source": { ... },
99
+
"data": { ... },
100
+
"truncated": false
101
+
}
102
+
}
103
+
```
104
+
105
+
| Field | Type | Description |
106
+
| --- | --- | --- |
107
+
|`capture_session_id`| string | Pipeline-assigned ID for the capture session (not a CDP concept). |
|`event.truncated`| bool |`true` if `data` was nulled to fit the 1 MB pipeline limit. |
113
+
114
+
### Source object
115
+
116
+
```json
117
+
"source": {
118
+
"kind": "cdp",
119
+
"event": "Network.requestWillBeSent",
120
+
"metadata": {
121
+
"cdp_session_id": "...",
122
+
"target_id": "...",
123
+
"target_type": "page"
124
+
}
125
+
}
126
+
```
127
+
128
+
| Field | Description |
129
+
| --- | --- |
130
+
|`event`| The raw CDP method that triggered the event (e.g. `Network.requestWillBeSent`). Empty for computed events. |
131
+
|`metadata.cdp_session_id`| The CDP WebSocket session multiplexer ID for this target. Changes if Chrome restarts. |
132
+
|`metadata.target_id`| Stable identifier for the browser target (tab/window). Survives navigations within the same tab. |
133
+
|`metadata.target_type`| Target type as reported by Chrome: `page`, `iframe`, `worker`, etc. |
134
+
135
+
### CDP identity primer
136
+
137
+
Five IDs appear across events. Understanding how they nest prevents confusion:
138
+
139
+
```
140
+
target_id <- one per tab/window; stable across navigations
141
+
└── cdp_session_id <- WebSocket multiplexer channel to that target; resets on Chrome restart
142
+
└── frame_id <- one per frame (top-level or iframe); changes on navigation
143
+
└── loader_id <- one per document load; links a navigation to its network requests
144
+
└── request_id <- one per request (stable across redirects in a chain)
145
+
```
146
+
147
+
| ID | Where it appears | What it identifies |
148
+
| --- | --- | --- |
149
+
|`target_id`|`source.metadata`, most `data` objects | The browser tab. Use this to group all events from one tab session. |
150
+
|`cdp_session_id`|`source.metadata`| The WebSocket sub-channel. Not stable across reconnects. |
151
+
|`frame_id`|`page_navigation`, `network_request`, `network_response`, `network_loading_failed`| The frame the request or navigation belongs to. Top-level frame has no `parent_frame_id`. |
152
+
|`source_frame_id`|`page_layout_shift`| The frame where the layout shift occurred. Distinct from the nav context `frame_id`, which is always the top-level navigated frame. |
153
+
|`loader_id`|`page_navigation`, `network_request`, `network_response`| The document load that owns a request. Join `network_request.loader_id` to `page_navigation.loader_id` to correlate requests with the navigation that triggered them. |
154
+
|`request_id`|`network_request`, `network_response`, `network_loading_failed`| A single request chain (including redirects). Links request to its eventual response or failure. |
155
+
156
+
### Navigation context fields
157
+
158
+
Most event `data` objects include a nav context block stamped at the last `page_navigation`. These fields reflect the top-level frame most recently navigated in the session:
159
+
160
+
| Field | Description |
161
+
| --- | --- |
162
+
|`session_id`| Same as `source.metadata.cdp_session_id`. Repeated for data-only consumers. |
163
+
|`frame_id`| Frame ID of the navigated top-level frame. |
164
+
|`loader_id`| Loader ID of the current document. |
165
+
|`url`| URL of the current page at the time of the last navigation. |
166
+
|`nav_seq`| Monotonically increasing counter, incremented on each `page_navigation`. Use it to detect that the page has navigated between two events in the same session. |
0 commit comments