Skip to content

Commit

Permalink
don't break pages which load child frames quickly
Browse files Browse the repository at this point in the history
If a page loads a child frame before the top frame has finished loading,
we'd treat the child frame as the top-level frame, and the original
frame would never get all of its nodes.

This can be seen in the addition to TestLoadIframe; before the fix, that
test would hang.

The problem was that we treated all navigated frames as top-level
frames, when that's not true. Only when a newly navigated frame has no
parent frame should we treat it as our new top-level frame.

Fixes #304.
  • Loading branch information
mvdan committed Apr 22, 2019
1 parent ed7b483 commit dd67f50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions nav_test.go
Expand Up @@ -348,6 +348,7 @@ func TestLoadIframe(t *testing.T) {
// iframes.
Sleep(10 * time.Millisecond),
// WaitVisible(`#form`, ByID), // for the nested form.html
WaitVisible(`#parent`, ByID), // for iframe.html
}); err != nil {
t.Fatal(err)
}
Expand Down
6 changes: 5 additions & 1 deletion target.go
Expand Up @@ -205,7 +205,11 @@ func (t *Target) pageEvent(ev interface{}) {
switch e := ev.(type) {
case *page.EventFrameNavigated:
t.frames[e.Frame.ID] = e.Frame
t.cur = e.Frame
if e.Frame.ParentID == "" {
// This frame is only the new top-level frame if it has
// no parent.
t.cur = e.Frame
}
return

case *page.EventFrameAttached:
Expand Down
1 change: 1 addition & 0 deletions testdata/iframe.html
Expand Up @@ -4,6 +4,7 @@
<title>page with an iframe</title>
</head>
<body>
<div id="parent"></div>
<iframe src="form.html"></iframe>
</body>
</html>

0 comments on commit dd67f50

Please sign in to comment.