From dd67f508b68d7aa9b11617f928423dd61c0d0e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 22 Apr 2019 15:30:07 +0700 Subject: [PATCH] don't break pages which load child frames quickly 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. --- nav_test.go | 1 + target.go | 6 +++++- testdata/iframe.html | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/nav_test.go b/nav_test.go index 89ff6035..68750567 100644 --- a/nav_test.go +++ b/nav_test.go @@ -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) } diff --git a/target.go b/target.go index 8320b0f9..b9cf39f8 100644 --- a/target.go +++ b/target.go @@ -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: diff --git a/testdata/iframe.html b/testdata/iframe.html index 72a59e06..37e74046 100644 --- a/testdata/iframe.html +++ b/testdata/iframe.html @@ -4,6 +4,7 @@ page with an iframe +