@@ -134,25 +134,28 @@ func (m *Monitor) handleConsole(p cdpRuntimeConsoleAPICalledParams, sessionID st
134134 for _ , a := range p .Args {
135135 argValues = append (argValues , consoleArgString (a ))
136136 }
137- data , _ := json .Marshal (map [string ]any {
137+ eventType := EventConsoleLog
138+ if p .Type == "error" {
139+ eventType = EventConsoleError
140+ }
141+ cs := m .computedFor (sessionID )
142+ data := cs .navDataWith (map [string ]any {
138143 "level" : p .Type ,
139144 "text" : text ,
140145 "args" : argValues ,
141146 "stack_trace" : p .StackTrace ,
142147 })
143- eventType := EventConsoleLog
144- if p .Type == "error" {
145- eventType = EventConsoleError
146- }
147148 m .publishEvent (eventType , events .CategoryConsole , events.Source {Kind : events .KindCDP }, "Runtime.consoleAPICalled" , data , sessionID )
148149}
149150
150151func (m * Monitor ) handleExceptionThrown (ctx context.Context , p cdpRuntimeExceptionThrownParams , sessionID string ) {
151- data , _ := json .Marshal (map [string ]any {
152+ cs := m .computedFor (sessionID )
153+ // source_url is the script file URL; distinct from nav context's url (the page URL).
154+ data := cs .navDataWith (map [string ]any {
152155 "text" : p .ExceptionDetails .Text ,
153156 "line" : p .ExceptionDetails .LineNumber ,
154157 "column" : p .ExceptionDetails .ColumnNumber ,
155- "url" : p .ExceptionDetails .URL ,
158+ "source_url" : p .ExceptionDetails .URL ,
156159 "stack_trace" : p .ExceptionDetails .StackTrace ,
157160 })
158161 m .publishEvent (EventConsoleError , events .CategoryConsole , events.Source {Kind : events .KindCDP }, "Runtime.exceptionThrown" , data , sessionID )
@@ -199,18 +202,23 @@ func (m *Monitor) handleBindingCalled(p cdpRuntimeBindingCalledParams, sessionID
199202 m .bindingLastSeen [rateKey ] = now
200203 m .bindingRateMu .Unlock ()
201204
202- m .publishEvent (header .Type , events .CategoryInteraction , events.Source {Kind : events .KindCDP }, "Runtime.bindingCalled" , payload , sessionID )
205+ var payloadMap map [string ]any
206+ _ = json .Unmarshal (payload , & payloadMap )
207+ cs := m .computedFor (sessionID )
208+ m .publishEvent (header .Type , events .CategoryInteraction , events.Source {Kind : events .KindCDP }, "Runtime.bindingCalled" , cs .navDataWith (payloadMap ), sessionID )
203209}
204210
205211// handleTimelineEvent processes PerformanceTimeline layout-shift events.
206212func (m * Monitor ) handleTimelineEvent (p cdpPerformanceTimelineEventAddedParams , sessionID string ) {
207213 if p .Event .Type != timelineEventLayoutShift {
208214 return
209215 }
216+ // source_frame_id is the frame where the shift occurred; distinct from nav
217+ // context's frame_id (the top-level navigated frame).
210218 ev := map [string ]any {
211- "frame_id " : p .Event .FrameID ,
212- "time" : p .Event .Time ,
213- "duration" : p .Event .Duration ,
219+ "source_frame_id " : p .Event .FrameID ,
220+ "time" : p .Event .Time ,
221+ "duration" : p .Event .Duration ,
214222 }
215223 var shift cdpLayoutShiftDetails
216224 if p .Event .LayoutShiftDetails != nil && json .Unmarshal (p .Event .LayoutShiftDetails , & shift ) == nil {
@@ -230,9 +238,10 @@ func (m *Monitor) handleTimelineEvent(p cdpPerformanceTimelineEventAddedParams,
230238 "node_id" : lcp .NodeID ,
231239 }
232240 }
233- data , _ := json .Marshal (ev )
241+ cs := m .computedFor (sessionID )
242+ data := cs .navDataWith (ev )
234243 m .publishEvent (EventLayoutShift , events .CategoryPage , events.Source {Kind : events .KindCDP }, "PerformanceTimeline.timelineEventAdded" , data , sessionID )
235- if cs := m . computedFor ( sessionID ); cs != nil {
244+ if cs != nil {
236245 cs .onLayoutShift ()
237246 }
238247}
@@ -415,7 +424,17 @@ func (m *Monitor) handleLoadingFailed(p cdpNetworkLoadingFailedParams, sessionID
415424}
416425
417426func (m * Monitor ) handleFrameNavigated (p cdpPageFrameNavigatedParams , sessionID string ) {
427+ // Pre-fetch target info and computedState before acquiring pendReqMu to
428+ // avoid a pendReqMu → sessionsMu ordering cycle.
429+ m .sessionsMu .RLock ()
430+ info := m .sessions [sessionID ]
431+ cs := m .computedStates [sessionID ]
432+ m .sessionsMu .RUnlock ()
433+
418434 data , _ := json .Marshal (map [string ]any {
435+ "session_id" : sessionID ,
436+ "target_id" : info .targetID ,
437+ "target_type" : info .targetType ,
419438 "url" : p .Frame .URL ,
420439 "frame_id" : p .Frame .ID ,
421440 "parent_frame_id" : p .Frame .ParentID ,
@@ -428,13 +447,6 @@ func (m *Monitor) handleFrameNavigated(p cdpPageFrameNavigatedParams, sessionID
428447 if p .Frame .ParentID == "" {
429448 m .mainSessionID .Store (sessionID )
430449
431- // Pre-fetch target info and computedState under sessionsMu before acquiring
432- // pendReqMu, to avoid a pendReqMu → sessionsMu ordering cycle.
433- m .sessionsMu .RLock ()
434- info := m .sessions [sessionID ]
435- cs := m .computedStates [sessionID ]
436- m .sessionsMu .RUnlock ()
437-
438450 navCtx := navContext {
439451 sessionID : sessionID ,
440452 targetID : info .targetID ,
0 commit comments