Skip to content

Commit

Permalink
Add fix to prevent iframe panic on navigation
Browse files Browse the repository at this point in the history
The change prevents the iframe child frames from being removed when a
detach event comes in from Chrome.

An iframe seems to be associated to multiple sessions. The initial
sessions that is linked to the mainframe that the iframe belongs to and
its own session. When the page navigates, a detach event arrives with
the initial session and a swap type for the iframe. The iframe though
is associated to its own session. In this scenario we want to avoid
removing frames, which prevents panics occurring when the iframe
navigates.
  • Loading branch information
ankur22 committed May 24, 2024
1 parent c5c9435 commit 4a6e086
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions common/frame_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,24 @@ func (m *FrameManager) frameDetached(frameID cdp.FrameID, reason cdppage.FrameDe
return
}

// This helps prevent an iframe and its child frames from being removed
// when the type of detach is a swap. After this detach event usually
// the iframe navigates, which requires the frames to be present for the
// navigate to work.
fs := m.page.getFrameSession(frameID)
if fs != nil {
m.logger.Debugf("FrameManager:frameDetached:sessionFound",
"fmid:%d fid:%v fsID1:%v fsID2:%v found session for frame",
m.ID(), frameID, fs.session.ID(), m.session.ID())

if fs.session.ID() != m.session.ID() {
m.logger.Debugf("FrameManager:frameDetached:notSameSession:return",
"fmid:%d fid:%v event session and frame session do not match",
m.ID(), frameID)
return
}
}

if reason == cdppage.FrameDetachedReasonSwap {
// When a local frame is swapped out for a remote
// frame, we want to keep the current frame which is
Expand Down

0 comments on commit 4a6e086

Please sign in to comment.