grafana/k6 · error
evaluating handle for element
Error message
evaluating handle for element: %w
What it means
Wrap of an ExecutionContext.EvalHandle failure in BaseJSHandle.EvaluateHandle: like Evaluate, the page function runs in the browser with the handle as first argument, but the result is expected to be a new remote object wrapped as a JSHandle. The wrapped error indicates the evaluation threw in the page (exception or syntax error), or the result could not be materialized as a handle (e.g., the function returned a primitive that cannot be referenced as a remote object).
Solutions
- Ensure the page function returns an object or DOM node rather than a primitive
- Check the function for runtime exceptions by testing it in devtools
- Re-acquire the source handle if navigation may have invalidated its execution context
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at internal/js/modules/k6/browser/common/js_handle.go:151 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/ac246389415e1c55.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/browser/common/js_handle.go:151
}
// Evaluate will evaluate provided page function within an execution context.
func (h *BaseJSHandle) Evaluate(pageFunc string, args ...any) (any, error) {
args = append([]any{h}, args...)
res, err := h.execCtx.Eval(h.ctx, pageFunc, args...)
if err != nil {
return nil, fmt.Errorf("evaluating element: %w", err)
}
return res, nil
}
// EvaluateHandle will evaluate provided page function within an execution context.
func (h *BaseJSHandle) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) {
args = append([]any{h}, args...)
eh, err := h.execCtx.EvalHandle(h.ctx, pageFunc, args...)
if err != nil {
return nil, fmt.Errorf("evaluating handle for element: %w", err)
}
return eh, nil
}
// GetProperties retreives the JS handle's properties.
func (h *BaseJSHandle) GetProperties() (map[string]JSHandleAPI, error) {
handles, err := h.getProperties()
if err != nil {
return nil, err
}
jsHandles := make(map[string]JSHandleAPI, len(handles))
for k, v := range handles {
jsHandles[k] = v
}
return jsHandles, nilView on GitHub (pinned to 01ffac6f24)