{"record":{"id":"4e0c6ad3c2ac8199","repo":"grafana/k6","slug":"evaluating-element-w","errorCode":null,"errorMessage":"evaluating element: %w","messagePattern":"evaluating element: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/browser/common/js_handle.go","lineNumber":140,"sourceCode":"\th.disposed = true\n\tif h.remoteObject.ObjectID == \"\" {\n\t\treturn nil\n\t}\n\tact := runtime.ReleaseObject(h.remoteObject.ObjectID)\n\tif err := act.Do(cdp.WithExecutor(h.ctx, h.session)); err != nil {\n\t\treturn fmt.Errorf(\"disposing element with ID %s: %w\",\n\t\t\th.remoteObject.ObjectID, err)\n\t}\n\n\treturn nil\n}\n\n// Evaluate will evaluate provided page function within an execution context.\nfunc (h *BaseJSHandle) Evaluate(pageFunc string, args ...any) (any, error) {\n\targs = append([]any{h}, args...)\n\tres, err := h.execCtx.Eval(h.ctx, pageFunc, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"evaluating element: %w\", err)\n\t}\n\n\treturn res, nil\n}\n\n// EvaluateHandle will evaluate provided page function within an execution context.\nfunc (h *BaseJSHandle) EvaluateHandle(pageFunc string, args ...any) (JSHandleAPI, error) {\n\targs = append([]any{h}, args...)\n\teh, err := h.execCtx.EvalHandle(h.ctx, pageFunc, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"evaluating handle for element: %w\", err)\n\t}\n\n\treturn eh, nil\n}\n\n// GetProperties retreives the JS handle's properties.\nfunc (h *BaseJSHandle) GetProperties() (map[string]JSHandleAPI, error) {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/browser/common/js_handle.go#L122-L158","documentation":"Wrap of an ExecutionContext.Eval failure in BaseJSHandle.Evaluate: the provided page function is evaluated in the browser with the handle prepended as the first argument, and the wrapped error fires when evaluation itself fails — a JS exception thrown inside the page function, a syntax error in the function string, the execution context being destroyed by navigation, or the handle's object having been released.","triggerScenarios":"Thrown at internal/js/modules/k6/browser/common/js_handle.go:140 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the page function compiles — test it in the browser devtools console","Guard against navigation: wait for load/lifecycle events before evaluating","Re-query the element handle if it may have been detached by DOM changes","Wrap risky logic inside the page function in try/catch and return a sentinel value"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}