Skip to content
This repository has been archived by the owner on Jan 30, 2025. It is now read-only.

Fix iframe panic on navigation #1346

Merged
merged 3 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 7 additions & 5 deletions common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ func (fs *FrameSession) initFrameTree() error {
return fmt.Errorf("got a nil page frame tree")
}

// Any new frame may have a child frame, not just mainframes.
fs.handleFrameTree(frameTree, fs.isMainFrame())

if fs.isMainFrame() {
fs.handleFrameTree(frameTree)
fs.initRendererEvents()
}
return nil
Expand Down Expand Up @@ -577,19 +579,19 @@ func (fs *FrameSession) isMainFrame() bool {
return fs.targetID == fs.page.targetID
}

func (fs *FrameSession) handleFrameTree(frameTree *cdppage.FrameTree) {
func (fs *FrameSession) handleFrameTree(frameTree *cdppage.FrameTree, initialFrame bool) {
fs.logger.Debugf("FrameSession:handleFrameTree",
"sid:%v tid:%v", fs.session.ID(), fs.targetID)
"fid:%v sid:%v tid:%v", frameTree.Frame.ID, fs.session.ID(), fs.targetID)

if frameTree.Frame.ParentID != "" {
fs.onFrameAttached(frameTree.Frame.ID, frameTree.Frame.ParentID)
}
fs.onFrameNavigated(frameTree.Frame, true)
fs.onFrameNavigated(frameTree.Frame, initialFrame)
if frameTree.ChildFrames == nil {
return
}
for _, child := range frameTree.ChildFrames {
fs.handleFrameTree(child)
fs.handleFrameTree(child, initialFrame)
}
}

Expand Down
Loading