grafana/k6 · error
evaluating JS
Error message
evaluating JS: %w
What it means
Returned by Frame.EvaluateWithContext when evaluating the provided page function in the frame's main world fails. The wrapped error is the evaluation failure: JS exception in the page function, destroyed execution context, argument conversion failure, or a CDP error.
Solutions
- Fix JS exceptions in the evaluated page function (check error text)
- Evaluate after the frame loads; retry post-navigation
- Pass only serializable arguments
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/frame.go:868 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@3fcf5388d7 (2026-08-18).
Data as JSON: /api/errors/0c388c2f1106eeec.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/frame.go:876
return nil
}
// EvaluateWithContext will evaluate provided page function within an execution context.
// The passed in context will be used instead of the frame's context. The context must
// be a derivative of one that contains the sobek runtime.
func (f *Frame) EvaluateWithContext(ctx context.Context, pageFunc string, args ...any) (any, error) {
f.log.Debugf("Frame:EvaluateWithContext", "fid:%s furl:%q", f.ID(), f.URL())
f.waitForExecutionContext(mainWorld)
opts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := f.evaluate(ctx, mainWorld, opts, pageFunc, args...)
if err != nil {
return nil, fmt.Errorf("evaluating JS: %w", err)
}
applySlowMo(ctx)
return result, nil
}
// Evaluate will evaluate provided page function within an execution context.
func (f *Frame) Evaluate(pageFunc string, args ...any) (any, error) {
f.log.Debugf("Frame:Evaluate", "fid:%s furl:%q", f.ID(), f.URL())
return f.EvaluateWithContext(f.ctx, pageFunc, args...)
}
// EvaluateGlobal will evaluate the given JS code in the global object.
func (f *Frame) EvaluateGlobal(ctx context.Context, js string) error {
action := runtime.Evaluate(js).WithAwaitPromise(true)
View on GitHub (pinned to 3fcf5388d7)