@@ -242,6 +242,7 @@ func (b *Bridge) SetupEventSubscriptions() {
242242 }
243243
244244 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
245+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
245246
246247 // Skip intermediate about:blank navigations during reload/redirect.
247248 // Juggler emits navigation to about:blank before navigating to the real URL.
@@ -285,21 +286,21 @@ func (b *Bridge) SetupEventSubscriptions() {
285286
286287 // Emit lifecycle events in Chrome's order
287288 b .emitEvent ("Page.lifecycleEvent" , map [string ]interface {}{
288- "frameId" : ev . FrameID ,
289+ "frameId" : cdpFrameID ,
289290 "loaderId" : loaderId ,
290291 "name" : "init" ,
291292 "timestamp" : 0 ,
292293 }, cdpSessionID )
293294 b .emitEvent ("Page.lifecycleEvent" , map [string ]interface {}{
294- "frameId" : ev . FrameID ,
295+ "frameId" : cdpFrameID ,
295296 "loaderId" : loaderId ,
296297 "name" : "commit" ,
297298 "timestamp" : 0 ,
298299 }, cdpSessionID )
299300
300301 b .emitEvent ("Page.frameNavigated" , map [string ]interface {}{
301302 "frame" : map [string ]interface {}{
302- "id" : ev . FrameID ,
303+ "id" : cdpFrameID ,
303304 "url" : ev .URL ,
304305 "loaderId" : loaderId ,
305306 "securityOrigin" : "" ,
@@ -324,6 +325,7 @@ func (b *Bridge) SetupEventSubscriptions() {
324325 }
325326
326327 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
328+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
327329
328330 // Use the same loaderId as the navigation that triggered this event
329331 b .loaderMapMu .RLock ()
@@ -339,13 +341,13 @@ func (b *Bridge) SetupEventSubscriptions() {
339341 "timestamp" : 0 ,
340342 }, cdpSessionID )
341343 b .emitEvent ("Page.lifecycleEvent" , map [string ]interface {}{
342- "frameId" : ev . FrameID ,
344+ "frameId" : cdpFrameID ,
343345 "loaderId" : loaderId ,
344346 "name" : "load" ,
345347 "timestamp" : 0 ,
346348 }, cdpSessionID )
347349 b .emitEvent ("Page.frameStoppedLoading" , map [string ]interface {}{
348- "frameId" : ev . FrameID ,
350+ "frameId" : cdpFrameID ,
349351 }, cdpSessionID )
350352
351353 // NOTE: Isolated worlds are NOT re-emitted here.
@@ -355,7 +357,7 @@ func (b *Bridge) SetupEventSubscriptions() {
355357 "timestamp" : 0 ,
356358 }, cdpSessionID )
357359 b .emitEvent ("Page.lifecycleEvent" , map [string ]interface {}{
358- "frameId" : ev . FrameID ,
360+ "frameId" : cdpFrameID ,
359361 "loaderId" : loaderId ,
360362 "name" : "DOMContentLoaded" ,
361363 "timestamp" : 0 ,
@@ -424,6 +426,8 @@ func (b *Bridge) SetupEventSubscriptions() {
424426 b .latestCtx [jugglerSessionID ] = ev .ExecutionContextID
425427 b .latestCtxMu .Unlock ()
426428
429+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .AuxData .FrameID )
430+
427431 b .emitEvent ("Runtime.executionContextCreated" , map [string ]interface {}{
428432 "context" : map [string ]interface {}{
429433 "id" : ctxID ,
@@ -433,7 +437,7 @@ func (b *Bridge) SetupEventSubscriptions() {
433437 "auxData" : map [string ]interface {}{
434438 "isDefault" : true ,
435439 "type" : "default" ,
436- "frameId" : ev . AuxData . FrameID ,
440+ "frameId" : cdpFrameID ,
437441 },
438442 },
439443 }, cdpSessionID )
@@ -446,7 +450,7 @@ func (b *Bridge) SetupEventSubscriptions() {
446450 worlds := b .isolatedWorlds [cdpSessionID ]
447451 b .isolatedWorldsMu .RUnlock ()
448452
449- frameID := ev . AuxData . FrameID
453+ frameID := cdpFrameID
450454 for _ , w := range worlds {
451455 isoCtxID := b .nextCtxID ()
452456 b .ctxMapMu .Lock ()
@@ -570,10 +574,12 @@ func (b *Bridge) SetupEventSubscriptions() {
570574 }
571575
572576 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
577+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
578+ cdpParentFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .ParentFrameID )
573579
574580 b .emitEvent ("Page.frameAttached" , map [string ]interface {}{
575- "frameId" : ev . FrameID ,
576- "parentFrameId" : ev . ParentFrameID ,
581+ "frameId" : cdpFrameID ,
582+ "parentFrameId" : cdpParentFrameID ,
577583 }, cdpSessionID )
578584 })
579585
@@ -588,9 +594,10 @@ func (b *Bridge) SetupEventSubscriptions() {
588594 }
589595
590596 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
597+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
591598
592599 b .emitEvent ("Page.frameDetached" , map [string ]interface {}{
593- "frameId" : ev . FrameID ,
600+ "frameId" : cdpFrameID ,
594601 "reason" : "remove" ,
595602 }, cdpSessionID )
596603 })
@@ -657,6 +664,7 @@ func (b *Bridge) SetupEventSubscriptions() {
657664 }
658665
659666 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
667+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
660668
661669 cdpHeaders := map [string ]string {}
662670 for k , v := range ev .Headers {
@@ -698,7 +706,7 @@ func (b *Bridge) SetupEventSubscriptions() {
698706 "type" : "other" ,
699707 },
700708 "type" : resourceType ,
701- "frameId" : ev . FrameID ,
709+ "frameId" : cdpFrameID ,
702710 }, cdpSessionID )
703711 })
704712
@@ -719,6 +727,7 @@ func (b *Bridge) SetupEventSubscriptions() {
719727 }
720728
721729 cdpSessionID := b .resolveCDPSession (jugglerSessionID )
730+ cdpFrameID := b .cdpFrameIDForJugglerSession (jugglerSessionID , ev .FrameID )
722731
723732 b .emitEvent ("Network.responseReceived" , map [string ]interface {}{
724733 "requestId" : ev .RequestID ,
@@ -739,7 +748,7 @@ func (b *Bridge) SetupEventSubscriptions() {
739748 "fromPrefetchCache" : false ,
740749 "securityState" : "secure" ,
741750 },
742- "frameId" : ev . FrameID ,
751+ "frameId" : cdpFrameID ,
743752 }, cdpSessionID )
744753 })
745754
@@ -927,6 +936,11 @@ func (b *Bridge) SetupEventSubscriptions() {
927936 }
928937 }
929938
939+ cdpFrameID := ev .FrameID
940+ if cdpSessionID != "" {
941+ cdpFrameID = b .cdpFrameIDForSession (cdpSessionID , ev .FrameID )
942+ }
943+
930944 log .Printf ("[event] Browser.requestIntercepted → Fetch.requestPaused requestId=%s url=%s cdpSession=%s" , ev .RequestID , url , cdpSessionID )
931945
932946 // Emit Network.requestWillBeSent BEFORE Fetch.requestPaused.
@@ -946,7 +960,7 @@ func (b *Bridge) SetupEventSubscriptions() {
946960 "wallTime" : 0 ,
947961 "initiator" : map [string ]interface {}{"type" : "other" },
948962 "type" : resourceType ,
949- "frameId" : ev . FrameID ,
963+ "frameId" : cdpFrameID ,
950964 }, cdpSessionID )
951965
952966 b .emitEvent ("Fetch.requestPaused" , map [string ]interface {}{
@@ -959,7 +973,7 @@ func (b *Bridge) SetupEventSubscriptions() {
959973 "initialPriority" : "High" ,
960974 "referrerPolicy" : "strict-origin-when-cross-origin" ,
961975 },
962- "frameId" : ev . FrameID ,
976+ "frameId" : cdpFrameID ,
963977 "resourceType" : resourceType ,
964978 }, cdpSessionID )
965979 })
0 commit comments