@@ -142,6 +142,11 @@ func (m *Monitor) handleTimelineEvent(params json.RawMessage, sessionID string)
142142 m .computed .onLayoutShift ()
143143}
144144
145+ // handleNetworkRequest publishes network_request events.
146+ // NOTE: events include raw headers, post_data, and (on response) truncated
147+ // bodies which may contain cookies, bearer tokens, or other credentials.
148+ // This mirrors what CDP/DevTools itself exposes. Consumers should treat the
149+ // event stream as privileged data; opt-in redaction can be added later.
145150func (m * Monitor ) handleNetworkRequest (params json.RawMessage , sessionID string ) {
146151 var p cdpNetworkRequestParams
147152 if err := json .Unmarshal (params , & p ); err != nil {
@@ -156,7 +161,12 @@ func (m *Monitor) handleNetworkRequest(params json.RawMessage, sessionID string)
156161 initiatorType = raw .Type
157162 }
158163
164+ // Redirects reuse the same requestId and fire additional requestWillBeSent
165+ // events, but only a single loadingFinished fires per chain. Only increment
166+ // netPending for genuinely new requests to avoid permanently inflating the
167+ // counter and blocking network_idle.
159168 m .pendReqMu .Lock ()
169+ _ , isRedirect := m .pendingRequests [p .RequestID ]
160170 m .pendingRequests [p .RequestID ] = networkReqState {
161171 sessionID : sessionID ,
162172 method : p .Request .Method ,
@@ -180,7 +190,9 @@ func (m *Monitor) handleNetworkRequest(params json.RawMessage, sessionID string)
180190 }
181191 data , _ := json .Marshal (ev )
182192 m .publishEvent (EventNetworkRequest , events .DetailStandard , events.Source {Kind : events .KindCDP }, "Network.requestWillBeSent" , data , sessionID )
183- m .computed .onRequest ()
193+ if ! isRedirect {
194+ m .computed .onRequest ()
195+ }
184196}
185197
186198func (m * Monitor ) handleResponseReceived (params json.RawMessage , sessionID string ) {
0 commit comments