Skip to content

Commit

Permalink
avoid nil pointer dereference panics in enclosingFrame
Browse files Browse the repository at this point in the history
This should make the code more resilient; the crash was encountered in
some complex sites, but we were unable to reproduce it with a small HTML
test page.

The current best theory is that a node was used after it's replaced, so
its parent is no longer present in the frame's Nodes map. In that case,
return an empty FrameID, and the selector will try again with the new
and correct node.
  • Loading branch information
mvdan committed Jul 27, 2020
1 parent 446edaa commit c101504
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion target.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ func (t *Target) enclosingFrame(node *cdp.Node) cdp.FrameID {
t.frameMu.RLock()
top := t.frames[t.cur]
t.frameMu.RUnlock()
for node.FrameID == "" {
for {
if node == nil {
// Avoid crashing. This can happen if we're using an old
// node that has been replaced, for example.
return ""
}
if node.FrameID != "" {
break
}
node = top.Nodes[node.ParentID]
}
return node.FrameID
Expand Down

0 comments on commit c101504

Please sign in to comment.