From 74ed9fef18afff47540979b6309c3425162d3d54 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Thu, 21 Mar 2024 17:06:48 +0000 Subject: [PATCH] Fix possible NPD 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. --- common/frame_session.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/common/frame_session.go b/common/frame_session.go index 4ed5c4af5..5fa411e7c 100644 --- a/common/frame_session.go +++ b/common/frame_session.go @@ -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 }