Closed imiric closed 3 years ago
I looked into this today, but didn't have time to fix it properly. I'll describe the issue here in case someone else wants to pick it up, or for my own reference when I'm back after next week.
So here's what's happening:
*ExecutionContext
is nil
here (called on page.evaluate()
): https://github.com/grafana/xk6-browser/blob/1e901b4a803bb932a4efe60380d85ee3dec9209f/common/execution_context.go#L150Frame.nullContexts()
is called when handling the ExecutionContextsCleared
event: https://github.com/grafana/xk6-browser/blob/1e901b4a803bb932a4efe60380d85ee3dec9209f/common/frame_session.go#L189-L190page.goto()
is called in the script.So it's a race condition between page.evaluate()
and page.goto()
, and we should make sure that the ExecutionContext
is created in FrameSession.onExecutionContextCreated()
before Frame.Evaluate()
is called.
A signaling channel might work to indicate that the page/frame is loading, and all methods that depend on ExecutionContext
should wait until loading is done.
Although in general I'm not fond of the nulling of contexts when ExecutionContextsCleared
is received. Maybe we could use a safer alternative?
Thanks @imiric. I looked into this issue a bit now in the evening as well. Just created a PR: https://github.com/grafana/xk6-browser/pull/21
Testing examples/evaluate.js on 1e901b4 and Linux Chromium 93.0.4577.82 fails intermittently.
When running
k6 run examples/evaluate.js
it either works correctly and outputs:Or it fails with a VU panic:
Or with a
null
clientWidth
TypeError
: