Skip to content

Commit

Permalink
Fix possible NPD
Browse files Browse the repository at this point in the history
It doesn't make sense for this operation to continue when the frame is
not present, so return early. If the frame is present continue as
normal.
  • Loading branch information
ankur22 committed Mar 21, 2024
1 parent 0654e7a commit 74ed9fe
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions common/frame_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,18 +663,25 @@ func (fs *FrameSession) onExecutionContextCreated(event *cdpruntime.EventExecuti
if err := json.Unmarshal(auxData, &i); err != nil {
k6ext.Panic(fs.ctx, "unmarshaling executionContextCreated event JSON: %w", err)
}
var world executionWorld

frame, ok := fs.manager.getFrameByID(i.FrameID)
if ok {
if i.IsDefault {
world = mainWorld
} else if event.Context.Name == utilityWorldName && !frame.hasContext(utilityWorld) {
// In case of multiple sessions to the same target, there's a race between
// connections so we might end up creating multiple isolated worlds.
// We can use either.
world = utilityWorld
}
if !ok {
fs.logger.Debugf("FrameSession:onExecutionContextCreated:return",
"sid:%v tid:%v ectxid:%d missing frame",
fs.session.ID(), fs.targetID, event.Context.ID)
return
}

var world executionWorld
if i.IsDefault {
world = mainWorld
} else if event.Context.Name == utilityWorldName && !frame.hasContext(utilityWorld) {
// In case of multiple sessions to the same target, there's a race between
// connections so we might end up creating multiple isolated worlds.
// We can use either.
world = utilityWorld
}

if i.Type == "isolated" {
fs.isolatedWorlds[event.Context.Name] = true
}
Expand Down

0 comments on commit 74ed9fe

Please sign in to comment.