Skip to content

Commit

Permalink
Add nil check in attachFrameSession
Browse files Browse the repository at this point in the history
Being a bit more defensive against unexpected NPDs further along down
the line of execution.
  • Loading branch information
ankur22 committed Jan 14, 2025
1 parent 7fbcd21 commit 45e8b6a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion js/modules/k6/browser/common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,10 @@ func (fs *FrameSession) attachIFrameToTarget(ti *target.Info, sid target.Session
return fmt.Errorf("attaching iframe target ID %v to session ID %v: %w",
ti.TargetID, sid, err)
}
fs.page.attachFrameSession(cdp.FrameID(ti.TargetID), nfs)

if err := fs.page.attachFrameSession(cdp.FrameID(ti.TargetID), nfs); err != nil {
return err
}

return nil
}
Expand Down
9 changes: 8 additions & 1 deletion js/modules/k6/browser/common/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -682,11 +682,18 @@ func (p *Page) getOwnerFrame(apiCtx context.Context, h *ElementHandle) (cdp.Fram
return frameID, nil
}

func (p *Page) attachFrameSession(fid cdp.FrameID, fs *FrameSession) {
func (p *Page) attachFrameSession(fid cdp.FrameID, fs *FrameSession) error {
p.logger.Debugf("Page:attachFrameSession", "sid:%v fid=%v", p.session.ID(), fid)

if fs == nil {
return errors.New("internal error: FrameSession is nil")
}

p.frameSessionsMu.Lock()
defer p.frameSessionsMu.Unlock()
fs.page.frameSessions[fid] = fs

return nil
}

func (p *Page) getFrameSession(frameID cdp.FrameID) (*FrameSession, bool) {
Expand Down

0 comments on commit 45e8b6a

Please sign in to comment.