grafana / xk6-browser

The browser module adds support for browser automation and end-to-end web testing via the Chrome Devtools Protocol to k6.
https://grafana.com/docs/k6/latest/javascript-api/k6-browser/
GNU Affero General Public License v3.0
342 stars 42 forks source link

Error handling navigation (nil `Frame`) #618

Open YazeedAlKhalaf opened 1 year ago

YazeedAlKhalaf commented 1 year ago

Brief summary

I want to click a button in the browser, the page doesn't even open fully.

xk6-browser version

k6 v0.40.0 ((devel), go1.19, darwin/arm64)

OS

macOS 12.6 (21G115)

Chrome version

106.0.5249.119

Docker version and image (if applicable)

No response

Steps to reproduce the problem

const browser = chromium.launch({
  headless: false, // make false for debugging
  slowMo: "500ms",
});
const context = browser.newContext();
const page = context.newPage();
page.goto(url, {
  waitUntil: "networkidle",
});

Expected behaviour

browser should not crash

Actual behaviour

browser crashes with the error:

WARN[0012] url:[REDACTED] method:POST err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=376
WARN[0012] url:[REDACTED].js method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=376
WARN[0012] url:[REDACTED].js method:GET err:fetching response body: No resource with given identifier found (-32000)  category="Response:bodySize:fetchBody" elapsed="0 ms" goroutine=376
INFO[0012] "[REDACTED]"  source=browser-console-api
panic: handling frameNavigated event to "about:blank": we either navigate top level or have old version of the navigated frame
running (00m12.4s), 1/1 VUs, 0 complete and 0 interrupted iterations
goroutine 383 [running]:-------------------------] 1 VUs  00m12.4s/10m0s  0/1 iters, 1 per VU
go.k6.io/k6/js/common.Throw(0x14000f409d0?, {0x1053f8ce0?, 0x14000e0c120?})
        go.k6.io/k6@v0.40.0/js/common/util.go:20 +0x58
github.com/grafana/xk6-browser/k6ext.Panic({0x105407a28, 0x14000886ab0}, {0x104e3690b, 0x27}, {0x1400042dde8, 0x2, 0x2})
        github.com/grafana/xk6-browser@v0.5.0/k6ext/panic.go:51 +0x278
github.com/grafana/xk6-browser/common.(*FrameSession).onFrameNavigated(0x140009b46e0, 0x14000e60b40, 0x20?)
        github.com/grafana/xk6-browser@v0.5.0/common/frame_session.go:650 +0x214
github.com/grafana/xk6-browser/common.(*FrameSession).initEvents.func1()
        github.com/grafana/xk6-browser@v0.5.0/common/frame_session.go:257 +0x650
created by github.com/grafana/xk6-browser/common.(*FrameSession).initEvents
        github.com/grafana/xk6-browser@v0.5.0/common/frame_session.go:228 +0x188
imiric commented 1 year ago

Hi there, thanks for opening this issue.

I'm not able to reproduce this on Linux with v0.5.0, but a few questions:

  1. How did you install xk6-browser? Are you using a binary from our releases page, or did you compile it yourself?

    Currently the k6 version command doesn't report the xk6-browser version, so that version string doesn't tell us much.

  2. Can you try building a custom binary with:

    xk6 build --output xk6-browser --with github.com/grafana/xk6-browser@09841f93a1de554352394f7ec295857726659572

    And running the test again with it? (Remember to run ./xk6-browser run from the same directory you run the above command in.)

    We've done some major fixes on the unstable branch that will be released soon in v0.6.0, so your issue might've been fixed already.

  3. If the issue persists with the new custom binary, how often does it happen? On every test run, occasionally (e.g. 1/10 test runs), etc.?

  4. Does the issue persist if you remove the waitUntil option from page.goto()? How about when you set headless: true, or remove the slowMo option?

Thanks!