-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page.waitForNavigation causes time out #226
Comments
I ran into this as well while testing the staging app. Looking into it. It could be considered part of #200 though. |
I've been looking into this issue, and it seems to happen when the navigation happens within the same document, e.g. by using the History API. In these cases the xk6-browser/common/frame_manager.go Lines 725 to 736 in 917b83e
... which is never emitted in these internal navigations, so the wait times out. I'm still not sure what the correct fix would be, and will keep investigating. |
Here's a test that reproduces the issue: package tests
import (
"net/http"
"testing"
"time"
"github.com/grafana/xk6-browser/common"
"github.com/stretchr/testify/require"
)
var navHTML = `
<html>
<head>
<title>History API navigation test</title>
</head>
<body>
<a id="navigate" href="#">Navigate</a>
<script>
const el = document.querySelector('a#navigate');
el.addEventListener('click', function(evt) {
evt.preventDefault();
history.pushState({}, 'navigated', '/nav2');
});
</script>
</body>
</html>
`
func TestWaitForFrameNavigationWithinDocument(t *testing.T) {
tb := newTestBrowser(t, withHTTPServer())
tb.withHandler("/nav", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html")
w.Write([]byte(navHTML))
}))
p := tb.NewPage(nil)
resp := p.Goto(tb.URL("/nav"), nil)
require.NotNil(t, resp)
el := p.Query("a#navigate")
require.NotNil(t, el)
// A click right away could possibly trigger navigation before we had a
// chance to call WaitForNavigation below, so give it some time to simulate
// the JS overhead, waiting for XHR response, etc.
time.AfterFunc(200*time.Millisecond, func() {
el.Click(nil)
})
p.WaitForNavigation(tb.rt.ToValue(&common.FrameWaitForNavigationOptions{
Timeout: 1000, // 1s
}))
} Running it results in:
I'm still looking into the possible fix. One possible option would be to emit a separate |
Previously WaitForNavigation assumed that a LifecycleEvent would always be fired, but this is not the case for navigation within the same document (e.g. via anchor links or the History API), so in those cases the call would timeout after 30s. The fix simply checks if we received a new document, otherwise it skips waiting for the LifecycleEvent. Even if that wait didn't time out, it would've failed with a nil pointer panic accessing event.newDocument.request. Closes #226
Previously WaitForNavigation assumed that a LifecycleEvent would always be fired, but this is not the case for navigation within the same document (e.g. via anchor links or the History API), so in those cases the call would timeout after 30s. The fix simply checks if we received a new document, otherwise it skips waiting for the LifecycleEvent. Even if that wait didn't time out, it would've failed with a nil pointer panic accessing event.newDocument.request. Closes #226
* Fix WaitForNavigation within the same document Previously WaitForNavigation assumed that a LifecycleEvent would always be fired, but this is not the case for navigation within the same document (e.g. via anchor links or the History API), so in those cases the call would timeout after 30s. The fix simply checks if we received a new document, otherwise it skips waiting for the LifecycleEvent. Even if that wait didn't time out, it would've failed with a nil pointer panic accessing event.newDocument.request. Closes #226 * Move static HTML to standalone file Resolves - #247 (comment) - #247 (comment) * Send empty struct instead of closing done channel Resolves #247 (comment) * Use Page.click() instead of ElementHandle.Click() Resolves #247 (comment)
Please see #200 (comment) and #200 (comment) for details.
Script Source
The text was updated successfully, but these errors were encountered: